The problem of assigning a variable value
1) constant let (it can be declared without assigning a value, but only once), variable var.
2) When the declaration is assigned, the compiler automatically calculates the type.
3) The display defines the variable type.
Let value:float = 4.0f
4) If you need to convert a value to a different type, use a cast.
Let AAA = 90;let bbb = ' Hello, world '; let CCC = BBB + String (AAA);
5) use \ () to convert the value to String
var a:int = 10;var B:int = 5;println ("sum = \ (A + B);");
6) array, dictionary generation
Second, control flow
In a if
statement, the condition must be a Boolean expression-which means that if score { ... }
code like this will make an error without being cloaked in comparison with 0.
var array = ["A", "B", "C", "D", "E"];array[4] = "Apple";p rintln (array); var dict = ["Key1": "Value1", "Key2": "value2"];d ict["Key3"] = "Value3";p rintln (dict); Null dictionary and empty array var emptyarray = [string] (), var emptydict = [string, float] (), var emptydictarray = [[[String, Float]] ();
Swift Grammar Chapter