gpt4 book ai didi

ios - Typhoon 依赖注入(inject)和 Swift 3 : Appdelegate isn't AnyObject

转载 作者:行者123 更新时间:2023-11-30 12:37:33 27 4
gpt4 key购买 nike

此代码适用于 Swift 2.3 中的 Typhoon 依赖注入(inject)库 (Obj-C),但不适用于 Swift 3:

AppDelegate:

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var rootViewController: RootViewController?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = self.rootViewController
self.window?.makeKeyAndVisible()

return true
}
...
}

应用程序组装:

    public class ApplicationAssembly: TyphoonAssembly {

public dynamic func config() -> AnyObject {
return TyphoonDefinition.withConfigName("Configuration.plist")
}

public dynamic func appDelegate() -> AnyObject {
return TyphoonDefinition.withClass(AppDelegate.self) {
(definition) in

definition!.injectProperty(#selector(ApplicationAssembly.rootViewController), with: self.rootViewController())
}
}
...
}

但是,对于任何预期返回“AnyObject”的 Swift 3 文件,ApplicationAssembly 中会显示以下错误:“没有‘withClass’候选者产生预期的上下文结果类型‘AnyObject’

有人可能了解 Obj-c Typhoon 代码库与 Swift 3 的不兼容性吗?

Screen capture of error line

最佳答案

您可能希望将返回类型从 AnyObject 切换为 Any

withClass 函数返回 Objective-C 中的 id 类型, see the source code :

+ (id)withClass:(Class)clazz block:(TyphoonBlockDefinitionInitializerBlock)block;

id 类型过去在 Swift 2 中映射到 AnyObject,但在 Swift 3 中它映射到 Any 以提高灵 active 。 You can read more about this change here.

关于ios - Typhoon 依赖注入(inject)和 Swift 3 : Appdelegate isn't AnyObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42677908/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com