0

I am new to Reactive Cocoa and to be honest it's not as simple to get into FRP as I thought it would be. Anyway, the concept is awesome and I'm trying to implement RAC in my current Swift project.

The situation:

MainTableViewController sets a property:

var userLocation = LocationManager()

LocationManager saves the location info in a dynamic variable.

dynamic var newLocation = [String]()

Back in MainTableViewController I tried to set up a RACSignal observing the newLocation variable:

rac_valuesForKeyPath("newLocation", observer: self.userLocation).subscribeNextAs { () -> () in
        println("New location received!")
    }

I checked other projects (in Objective-C) where it worked that way. But as soon as I compile the app xCode tells me:

2014-12-08 13:06:17.122 Test[28145:3242245] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Test.MainTableViewController 0x14c612570> valueForUndefinedKey:]: this class is not key value coding-compliant for the key newLocation.'

I'd appreciate any kind of help...

Thanks :)

flocbit
  • 313
  • 2
  • 10

1 Answers1

1

The observation is backwards. Try:

userLocation.rac_valuesForKeyPath("newLocation", observer: self).subscribeNextAs { (value) -> () in
    println("New location received!")
}
Dave Lee
  • 5,909
  • 33
  • 36
  • 1
    Dave you're my hero! ;) I don't know why I haven't figured that out earlier. Anyway, works like a charm. Thank you! – flocbit Dec 09 '14 at 08:58
  • does somebody know how to do it with the current swift2 branch? The swift 2 binding is being actively developed right now, as it seems – Fab1n Aug 26 '15 at 18:57