You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varoiympicStatus:String{
if isOlympicSport {return"\(name) is an Olympic sport"}else{return"\(name) is not an Olympic sport"}}}letchessBoxing=Sport2(name:"Chessboxing", isOlympicSport: false)print(chessBoxing.oiympicStatus)
Property observers
structProgress{vartask:Stringvaramount:Int}varprogress=Progress(task:"Loading data", amount:0)
progress.amount =30
progress.amount =80
progress.amount =100structProgress1{vartask:Stringvaramount:Int{
didSet {print("\(task) is now \(amount)% complete")}}}
Methods
structCity{varpopulation:Intfunc collectTaxes()->Int{return population *1000}}letlondon=City(population:9_000_000)
london.collectTaxes()
Mutating methods
structPerson{varname:Stringmutatingfunc makeAnonymous(){
name ="Anonymous"}}varperson=Person(name:"Ed")print(person.name)
person.makeAnonymous()print(person.name)
Properties and methods of strings
func travel1(action:()->Void){print("I'm getting ready to go.")action()print("I arrived!")}travel1(){print("I'm driving in my car")}travel{print("I'm driving in my car")}