SWIFT - KVO in xcode 6 beta 6.. observeValueForKeyPath no longer called

倖福魔咒の 提交于 2019-12-14 03:53:09

问题


I have been debugging my app from beta 3 to beta 6

I cannot seem to get observeValueForKeyPath to be called.. i put a breakpoint at the top of the function and nothing happens

self.gameScene.viewController.joystick.addObserver(self, forKeyPath: "relativePosition", options: .New, context: nil)

override func observeValueForKeyPath(keyPath: String!, ofObject object: AnyObject!, change: [NSObject : AnyObject]!, context: UnsafeMutablePointer<Void>) {

    if keyPath == "relativePosition" {
    // some code here 
    }
}

this code was working without a hitch before.. has something changed? I can't even get this to work in a more basic app.. is there something else I need to do?


回答1:


a property has to have the word "dynamic" in front of it to be observable now..

dynamic var relativePosition: CGPoint = CGPointZero


来源:https://stackoverflow.com/questions/25378034/swift-kvo-in-xcode-6-beta-6-observevalueforkeypath-no-longer-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!