Reference:
電腦人-SWIFT自學力!圖解140個iOSAPP開發範例給新手的超直覺設計指南
範例下載-Github https://github.com/WEI-WEI-SWIFT/iOS-Swift-Cookbook-2AU040
//********************************************************************
//********************************************************************
//********************** Protocol and Delegate ***********************
//********************************************************************
//********************************************************************
protocol BossDelegate{
func makeMoneyForBoss()
}
class Employee:BossDelegate{
func makeMoneyForBoss() {
print("水喔$$$$$")
}
}
class Boss{
var delegate:BossDelegate?
func gonnaMakeMoney(){
delegate?.makeMoneyForBoss()
}
}
let aBoss = Boss()
let aEmployee = Employee()
aBoss.delegate = aEmployee
aBoss.gonnaMakeMoney()
沒有留言:
張貼留言