3

I'm having issues trying to pass back userInfo via postNotification in Swift. What's strange is the code only breaks when I try to use userInfo -- if I post a notification with no data to a selector with no parameters, everything works. But when I try to pass back userInfo, I get a "unrecognized selector sent to instance" error. So something's wrong with my selector signature in my ViewController, but I can't figure out what.

Here is the code that breaks:

In my table view

let data = ["selection": selectedOption]
dismissViewControllerAnimated(true, completion: {NSNotificationCenter.defaultCenter().postNotificationName(wordsetPickedNotification, object: self, userInfo: data)})

In my view controller:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "wordsetPicked", name: wordsetPickedNotification, object: nil)
...
func wordsetPicked(n:NSNotification) {
    //do stuff
}
Derrick Hunt
  • 371
  • 3
  • 13

1 Answers1

2

Change selector: "wordsetPicked" to selector: "wordsetPicked:".

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • Thank you so much, that worked like a charm...can't believe I've been stuck on this for over an hour because of a colon! – Derrick Hunt Mar 10 '15 at 19:24
  • @DerrickHunt Glad it worked! If this fully resolves your issue, please click the check box to the left of my answer so other users will know that your issue is resolved. – Aaron Brager Mar 10 '15 at 19:31
  • Here's an explanation of why you need the colon - http://stackoverflow.com/questions/24007650/selector-in-swift/24007718#24007718 – tonethar Mar 13 '15 at 22:20