Swift Object-oriented (upper) class and struct body in--swift (bottom)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.