[英]Typhoon Dependency Injection and Swift 3: Appdelegate isn't AnyObject
This code works with Typhoon Dependency Injection library (Obj-C) in Swift 2.3 but doesn't in Swift 3: 该代码在Swift 2.3中可与台风依赖注入库(Obj-C)一起使用,但在Swift 3中则无法使用:
AppDelegate: 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
}
...
}
Application Assembly: 应用程序组装:
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())
}
}
...
}
However the following error is displayed in ApplicationAssembly for any Swift 3 file expected to return 'AnyObject': "No 'withClass' candidates produce the expected contextual result type 'AnyObject' 但是,对于任何预期返回“ AnyObject”的Swift 3文件,ApplicationAssembly中都会显示以下错误: “没有'withClass'候选者不会产生预期的上下文结果类型'AnyObject'
Might anyone have an insight into the incompatibility of the Obj-c Typhoon code base with Swift 3? 可能有人对Obj-c Typhoon代码库与Swift 3的不兼容性有深刻的了解吗?
You may want to switch the return type from AnyObject
to Any
. 您可能需要将返回类型从AnyObject
为Any
。
The withClass
function returns an id type in Objective-C, see the source code : withClass
函数在Objective-C中返回一个id类型, 请参见源代码 :
+ (id)withClass:(Class)clazz block:(TyphoonBlockDefinitionInitializerBlock)block;
The id
type used to be mapped to AnyObject
in Swift 2, but in Swift 3 it's mapped to Any
for increased flexibility. id
类型曾经在Swift 2中映射到AnyObject
,但是在Swift 3中,它被映射到Any
以提高灵活性。 You can read more about this change here. 您可以在此处阅读有关此更改的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.