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