From two to see now, almost two hours, are some of the conceptual things, mostly by understanding and memory, which involves the value of swift Reference and type reference, deep copy and shallow copy, etc., personally think these things are by understanding, the code is not clear, So the code is not written so much in the afternoon. Here are just a few lines of code to write.
// Enumeration // enum viewframe{// enumeration needs to start with a capital letter //case x//case Y//case width//case height//}
// multiple members can also be separated by commas enum viewframe{ case x, y, width, height}
var a = Viewframe.width//the values in the enumeration can be obtained through the. Syntax.A =. Height//When the type of a value is known, and then set his value, the type name is not required.Switcha{ Case. X:PRINTLN ("x Value") Case. Y:PRINTLN ("y value") Case. WIDTH:PRINTLN ("Width Value") Case. HEIGHT:PRINTLN ("Height Value")default: println ("other")}
enum Planet:int { case1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune}/ / int Here is the original value of the enumeration value, which is incremented when the original value is defined as int. // the RawValue property can access the original value, RawValue: The enumeration member can be found by the original value let x =2)
//classclassperson{//Create a person classvar name:string?var sex:string?var age=0}var Person1= Person ()//Creating ObjectsPerson1.name ="Chris"//assigning values to object propertiesprintln (person1.name)//A class is a reference type, and unlike a value type, a reference type is assigned to a variable, a constant, or is passed to a function, and the operation is not a copy of it. Therefore, the reference is made to the existing instance itself, not to its copy. For example, assigning an object to a and assigning A to B will change a or b at this time, essentially changing the same instance variable, which is called the reference type. (somewhat similar to the light copy in OC)//A struct is a value pass that can be understood as a deep copy object in OC//identity symbol, = = = equivalent to,!== is not equivalent to detecting two constants or whether a variable refers to the same instance variable
Swift starts learning _05 from scratch