1
NotificationCenter.default.addObserver(self, selector: Selector(("uploaded")), name: NSNotification.Name(rawValue: "uploaded"), object: nil)

I was writing name: "uploaded:" and xcode corrected it to the above code. The problem is when running the app i get unrecognized selector.

Any one know how to fix this to work with swift 3

2 Answers 2

3

Use the (identifier checking) #selector syntax:

Without parameter:

#selector(uploaded)

With parameter:

#selector(uploaded(_:))
1
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.update), name: NSNotification.Name(rawValue: "uploaded"), object: nil)

func update() {
      // do what you want
   }

please note that "ViewController" is the class name where your function is

1
  • Or, rather than replacing ViewController with the class name, just omit the class name altogether and it will use the current class.
    – Rob
    Oct 11, 2016 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.