我有以下代碼:使用字符串字面的Objective-C選擇器已被棄用,使用「#selector」,而不是
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")
下面的「警告」,其中說:
使用字符串字面的Objective-C選擇器已經過時,用「#selector」,而不是
警告並自動替換代碼:
UIApplicationShortcutItem.respondsToSelector(#selector(FBSDKAccessToken.new))
然而,這並不編譯,因爲new()
是unavailabe。 我應該在這種情況下使用什麼?
檢查這個......可能是你得到的東西http://stackoverflow.com/questions/36147831/syntax-selector-swift-2-2 –
爲什麼您選擇'new'測試?我沒有看到在這裏發送'new'消息的任何代碼。 –