Reputation: 2437
I have this observer
NotificationCenter.default.addObserver(self, selector: #selector(flashButtonDidPress(_:)), name: NSNotification.Name(rawValue: "flash"), object: nil)
And this delegate function
func flashButtonDidPress(_ title: String) {
cameraController.flashCamera(title)
}
Can someone explain me why I have the following error?
unrecognized selector sent to instance
Thanks in advance
EDIT: I am also accessing the function without the use of a notification
Upvotes: 1
Views: 836
Reputation: 285074
NotificationCenter
sends Notification
s, not String
s, use a second function to be called from somewhere else:
func flashButtonDidPress(_ notification: Notification) {
if let title = notification.userInfo?["title"] as? String {
flashCamera(with:title)
}
}
func flashCamera(with title: String)
{
cameraController.flashCamera(title)
}
pass the title
in the userInfo
dictionary when posting the notification, e.g.
let userInfo = ["title", title]
Upvotes: 3