我尝试使用let userInfo = notification.userInfo作为!字典< NSObject:AnyObject>将let userInfo = notification.userInfo替换为!的NSDictionary.但我收到一个错误:预计’>’完成通用参数列表.如何修复警告.
Xcode 7.1 OS X Yosemite
这是我的代码:
func keyboarDWillShow(notification: NSNotification) { let userInfo = notification.userInfo as! NSDictionary //warning let keyboardBounds = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() let duration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue let keyboardBoundsRect = self.vIEw.convertRect(keyboardBounds,toVIEw: nil) let keyboardinputVIEwFrame = self.finishVIEw!.frame let deltaY = keyboardBoundsRect.size.height let animations: (()->VoID) = { self.finishVIEw?.transform = CGAffinetransformMakeTranslation(0,-deltaY) } if duration > 0 { } else { animations() }}解决方法 NSNotification的userInfo属性已定义为(n可选)字典.
所以你根本不需要施放它,只需打开它.
func keyboarDWillShow(notification: NSNotification) { if let userInfo = notification.userInfo { ... }}
所有其余的代码应该按原样运行.
总结以上是内存溢出为你收集整理的swift – 来自'[NSObject:AnyObject]?’不相关的类型’NSDictionary’总是失败全部内容,希望文章能够帮你解决swift – 来自'[NSObject:AnyObject]?’不相关的类型’NSDictionary’总是失败所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)