台风注射 - 使用初始化器注入参数时发生崩溃

时间:2016-05-18 16:12:48

标签: ios swift dependency-injection typhoon

我正在关注Typhoon Coredata示例(https://github.com/appsquickly/Typhoon-CoreData-RAC-Example)以在swift中配置coredata。

但我在以下方法中遇到异常

public dynamic func managedObjectModel() -> AnyObject {
        return TyphoonDefinition.withClass(NSManagedObjectModel.self){
            (definition) in
            definition.useInitializer("contentsOfURL:"){
                (initializer) in
                 initializer.injectParameterWith(self.modelUrl())
            }
        }
    }

在上面的函数中,我试图将modelurl注入NSManagedObjectModel类的“contentsOfURL”方法。但我得到以下错误

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Method 'contentsOfURL:' not found on 'NSManagedObjectModel'. Did you include the required ':' characters to signify arguments?'

//

//NSManagedObjectModel class  
    public convenience init?(contentsOfURL url: NSURL)

1 个答案:

答案 0 :(得分:0)

definition.useInitializer("initWithContentsOfURL:")