1

Problematic code follows. [I hope that] the problem is wholly outlined in the question above. Thanks in advance. MJB.

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
    var some_string:NSString = "one"

    func application ( application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]? ) -> Bool
    {
        println("init...")
        self.addObserver( self, forKeyPath: "some_string", options: nil, context: nil )
        self.some_string = "two"
        return true
    }

    override func observeValueForKeyPath ( keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void> )
    {
        println("observeValueForKeyPath...")
    }
}
Joseph Beuys' Mum
  • 2,395
  • 2
  • 24
  • 50

1 Answers1

3

According to the Apple Documentation, you need to use the dynamic keyword to enable KVO for that property:

dynamic var some_string : NSString = "one"

Also, the class must inherit from NSObject to make this work, though in your case that is a given with UIResponder.

Erik
  • 12,730
  • 5
  • 36
  • 42
  • Thank you Erik, and thanks for being gracefully passive-aggressive. Sometimes we all need a bit of a poke in the face to make up us sharpen up. Apple docs, got it. – Joseph Beuys' Mum Mar 18 '15 at 11:35
  • 1
    Oh I wasn't trying to be, just giving you reference material. I had to look it up to find this gem out myself! – Erik Mar 20 '15 at 03:27