问题描述
安装Xcode 8 beta 6后,我收到一条警告说:
After installing Xcode 8 beta 6, I'm getting a warning saying:
的可选要求'application(_:didFinishLaunchingWithOptions :)'。
in my App Delegate.
有2个建议的修正可以使警告静音:
There are 2 suggested fixits to silence the warning:
- 将方法标记为私有
- 将@nonobjc添加到方法
执行任何操作都会使警告静音。但为什么需要这样做?
Doing either silences the warning. But why does this need to be done?
推荐答案
iOS 12 SDK更新
在iOS 12 SDK(随Xcode 10提供)中, UIApplicationLaunchOptionsKey
嵌套类型 UIApplication.LaunchOptionsKey
,所以你需要:
iOS 12 SDK Update
In the iOS 12 SDK (that ships with Xcode 10), UIApplicationLaunchOptionsKey
has now been renamed to the nested type UIApplication.LaunchOptionsKey
, so you'll want:
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// ...
}
iOS 10和11 SDK(Xcode 8和9)
此警告是由于 didFinishLaunchingWithOptions:
委托方法现在桥接到Swift作为 [UIApplicationLaunchOptionsKey:Any]?
,而不是 [NSObject:AnyObject]?
。
因此,您需要更新实施以反映此更改:
Therefore you'll need to update your implementation to reflect this change:
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
// ...
}
注意Xcode都没有建议的修复程序实际上会修复问题,它们只会隐藏你从Objective-C中实现的应用程序(_:didFinishLaunchingWithOptions:)
- 这意味着它实际上永远不会被调用。
Note that neither of Xcode's suggested fixes will actually fix the problem, they'll only conceal your implementation of application(_:didFinishLaunchingWithOptions:)
from Objective-C – meaning that it'll never actually get called.
这篇关于application(_:didFinishLaunchingWithOptions :)'几乎匹配可选要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!