I am trying to get the Keyboard height in swift 3 however I receive the following error,
Initialiser for conditional binding must have Optional type, not 'CGFloat'
for my guard let statement in the following
func keyboardWillShow(_ n:Notification) {
self.keyboardShowing = true
guard let keyboardHeight = (((n as NSNotification).userInfo! as NSDictionary).object(forKey: UIKeyboardFrameBeginUserInfoKey) as AnyObject).cgRectValue.size.height else {
return
}
}
So I am returning the CGFloat
value of the keyboard height for the keyboardWillShow
notification. So of course I know it will always return a value when it appears but seems since Swift 3 I have to return an option just in case.
How can I change the guard let
statement for swift 3 ?