Swift properties of classes and objects in object-oriented

Source: Internet
Author: User

The properties of classes and objects in Swift are divided into three types: storage properties, computed properties, and class properties.

ImportFoundationclass Person {//Storage attribute must be assigned an initial value  varScore1:int = -  varScore2:int = -  //Delay storage properties, assign when neededLazyvarDog:dog = Dog ()//Calculate attribute, cannot assign initial value, provide get and set method,  varSum:int {get {returnScore1 + Score2}}//Class attribute, can only be computed attribute, use class instead of object to call  //As Person.descClassvardesc:string {get {return "This is a person ."}  }//Construction methodInit () {println("This is a person .")}}class Dog {init () {println("This is one dog.")  }}varp = person ()println(PERSON.DESC)println(P.score1)println(P.score2)println(p.sum)println(P.dog)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Swift properties of classes and objects in object-oriented

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.