Learning from the Geek Academy
1 Import Foundation2 3 classUser {4 var name:string5 var age:int6 Init (name:string,age:int) {7Self.age = Age8Self.name =name9 }Ten } Onevar u1 = User (name:"He Yang", Age: at) Avar U2 = User (name:"He Yang", Age: at) -println (u1 = = =U2) -println (U1!== U2)//These two operators can only be used in comparison of reference types thevar U3 =U1 -println (u1 = = = U3)//point to the same object, of course the same - //If you want to compare reference types with = = or! =, you need to overload the two symbols with operator - + //Self keyword - /* + 1. Self in the constructor represents the instance that the constructor is initializing A 2. The self in the method represents the caller of the method at */ - - /*When to use a class, when to use a struct? - 1. The main purpose of the structure is to encapsulate a small amount of related simple data - 2. If you need to automatically replicate replicas when passing parameters or assignments, use the struct - 3. It is clear that the type does not inherit from another existing class or class in Note: Most of the time, the program should customize the class instead of the custom struct - */]
Swift Object-oriented (upper) class and struct body in--swift (bottom)