To make use of. Let to declare constants, so that var to declare the variable.? A constant value is not required at compile time, but you can only assign a value to it? once. So you can? Use constants to table? A value: You just need to decide, but you need to make it a lot of times.
NSLog ("--------------") var myvariable = myvariable = Mycontant = lable = "The Is"
the types of constants or variables must be the same as the values you assign to them. However, when declaring a type is optional and the declaration is assigned at the same time, the compiler will automatically infer the type. In the example of the upper plane, the compiler infers that myvariable is an integerbecause its initial value is an integer.
If the initial value is not provided? enough information (or no initial value), then you need to declare the type after the variable,? split with a colon.
Values are never implicitly converted to other types. If you need to convert a value to another type, explicitly convert it.
Let width = 94; Let widthlable = lable + (string) (width) NSLog (String (), widthlable)
Is there a simpler way to convert a value to a string? Method: Write the value in parentheses and write it before the parentheses. a backslash. For example:
Let apples =3
Let oranges = 5
Let applesummary = "I hava\ (apples)apples"
Let fruitsummary = "I hava\ (apples+oranges)pieces of fruit"
To create an empty array or dictionary, use the Initialize syntax.
Let Emptarray = [String] ()
Let emptdictionary = Dictionary<String,Float> ()
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Swift-definition and use of variables