swift : willSet + didSet 属性观察器
2015-03-09
阅读 1 分钟
2.9kclass StepCounter { var totalSteps: Int = 0 { willSet(newTotalSteps) { println("About to set totalSteps to (newTotalSteps)") } didSet { if totalSteps > oldValue { println("Added (totalSteps - oldValue) steps") } } } } let stepCounter = StepCounter() stepCounter.totalSteps = 200 // About to set...