The Willset and Didset features are used in the swift language to monitor property value changes other than initialization of properties
There's no need to say too much, just look at the code below and you'll get it quickly.
Import Foundationclass people:nsobject{//Common attribute var firstname:string =""var lastname:string =""var nickname:string =""//Calculated propertiesvar fullname:string {get {return nickname +""+ FirstName +"" +LastName}}//Normal property with Property monitor var age:int =0{//We need to do something before the age attribute changes.Willset {println ("Would set an new value \ (NewValue) to age") }//We need to update the nickname property after the Age property has changedDidset {println ("Age filed changed form \ (OldValue) to \ (age)")If age<10{nickname ="Little"}Else{nickname ="Big"}}}} func toString ()String {return"full Name: \ (fullName) "+ "" }var me = people () Me.firstname = "zhang "me.lastname = " sanme.age = 20println (Me.tostring ()) /* program output would set an new value of Ageage filed changed form 0 to 20Full name:big Zhang San, Age:20*/
Willset and Didset in Swift