Cannot Convert the expression's type 'CGRect' to type to 'NSCopying!' in swift I am trying to implement Keyboard notification in swift file.
// Called when the UIKeyboardDidShowNotification is sent.
func keyboardWasShown(aNotification :NSNotification)
{
var info = aNotification.userInfo
var kRect:CGRect = info[UIKeyboardFrameBeginUserInfoKey] as CGRect
var kbSize:CGSize = kRect.size
but not sure why am I getting this error?
You can't downcast the value you're pulling out of the dictionary to CGRect. It's an NSValue object, so you can easily get the rect value out of it with CGRectValue(). This should get you what you want.
func keyboardWasShown(aNotification: NSNotification) {
let info = aNotification.userInfo
if let rectValue = info[UIKeyboardFrameBeginUserInfoKey] as? NSValue {
let kbSize:CGSize = rectValue.CGRectValue().size
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With