correct declaration of variables in swift -


hi i'm new swift language, first of don't know if permitable topic i'm creating need understand , couldn't find information on web this

in swift realized there's couple of ways declaring variable , it's type. don't know differences , don't know use which..

correct me if wrong.. begin with: when

var = "when variable becomes type of string"  

but if type

var = 12 //it's type int  

and on.. apart declare these variables

var anything:int 

or

var anything:string 

so far i'm difference of declaring global variable as

var anything:string  

or

var anything:string = string() 

how decide use , where? thank you

i'll start backwards. difference between var anything:string , var anything:string = string()

the first 1 declares variable called anything of type string , second initializes calling string's constructor. in first case have tell swift's compiler expect variable - have value or nil. best thing if don't know declare optional:

var anything:string?

about types initialize var = 12, swift determines type context, in case int.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -