我有以下代码:
func setupShortcutItems(launchOptions: [NSObject: AnyObject]?) -> Bool { var shouldPerformAdditionalDelegateHandling: Bool = false if (UIApplicationShortcutItem.respondsToSelector("new")) { self.configDynamicShortcutItems() // If a shortcut was launched,display its information and take the appropriate action if let shortcutItem: UIApplicationShortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem { // When the app launched at the first time,this block can not called. self.handleShortCutItem(shortcutItem) // This will block "performActionForShortcutItem:completionHandler" from being called. shouldPerformAdditionalDelegateHandling = false } else { // normal app launch process without quick action self.launchWithoutQuickAction() } } else { // Less than iOS9 or later self.launchWithoutQuickAction() } return shouldPerformAdditionalDelegateHandling }
我在UIApplicationShortcutItem.respondsToSelector(“new”)上得到以下“警告”,它说:
Use of string literal for Objective-c selectors is deprecated,use ‘#selector’ instead
警告会自动替换代码:
UIApplicationShortcutItem.respondsToSelector(#selector(FBSDKAccessToken.new))
但是,由于new()不可用,因此无法编译.
在这种情况下我应该用什么?
解决方法
Xcode 7.3使用swift for iOS9.3 / watchOS2.2 / …
如果您以前使用过这一行代码:
NSNotificationCenter.defaultCenter().addObserver(self,selector: "updateResult:",name: "updateResult",object: nil)
您现在应该使用这一行代码:
NSNotificationCenter.defaultCenter().addObserver(self,selector: #selector(InterfaceController.updateResult(_:)),object: nil)
至少这是Xcode在代码中改变了几个字符后提供给我的.看起来似乎并不总是提供正确的解决方案,当你出现这个错误.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。