Attention :
This place is mainly for collecting what i has learnt about swift, the content is only on my thought, and maybe something are not exactly correct.
1 Swift introduces advanced types not found in OC, such as tuples. Tuples enable you to create and pass around groupings of values. You can use a tuple to return multiple values from a function as a single compound value.
2 Swift introduces optional types to handle the absence of a value, it says either "there is a value and it equals x " or "there isn't a value at all".
Optionals are similar to using nil with pointers in OC, but they work for any type, not just classes.Optionals are safer and more expressive than nil pointers in OC and at the heart of many of swift's most powerful feature (not correctly know what this mean)
3 swift is a type safe language. Optionals are an an example.
4 can declare multiple constants or multiple variables on a single line, separated by commas:
var x = 0.0, y = 0.0, z = 0.0
5 type annotation : var welcomeMessage: String var blue, red, green: UIColor
6 once you've declared a constant or variable of a certain type, you cann't redeclare it again with the same name, or change it to store values of a different type. Nor can you change a constant into a variable or a variable into a constant
7 string interpolation : include the name of a constant or variable as a placeholder in a longer string, and to prompt Swift to replace it with the current value of that constant or variable l.g.:println("The current value of string if \(xxx)")
8 Commnets: unlike multiline comments in C, multiline comments in Swift can be nested inside other multiline comments
9 Swift always choose Double(rather than Float )when inferring the type of floating-point numbers
10 tuples are useful for temporary groups of related values. They are not suited to the creation of complex data structures. If your data structure is likely to persist beyong a temporary scope, model it as a class or structure, rather than as a tuple
11 Optionals:
nil in OC meanins "the absence of a valid object", it only works for objects--it doesn't work for structures, basic C types, or enumeration values, for these types, OC methods typically return a special value(such as NSNotFound); Optionals means "there is a value and it equals x or there isn't a value at all", it is for any type at all, without the need for special constants.
当某个variable 可能为空时,使用optionals,like:
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell