DrCachetes
DrCachetes

Reputation: 954

how to pass an NSNotification as parameter to the selector function in Swift

I'm trying to implement an UIKeyboardWillShowNotification to handle my view position when the keyboard appear. I add my observer:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow", name: UIKeyboardWillShowNotification, object: nil)

Then I have the keyboardWillShow function:

func keyboardWillShow(notification: NSNotification){
    //Need to access to the notification here
}

In the function keyboardWillShow I need to receive the NSNotification to get access to the user information but I get this error:

"unrecognized selector sent to instance 0x7fd993e7d020"

Upvotes: 2

Views: 1578

Answers (1)

Logan
Logan

Reputation: 53112

You forgot the colon :. Change it to this:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)

Upvotes: 9

Related Questions