无法注入属性,找不到setter选择器

时间:2015-03-09 23:09:56

标签: ios swift typhoon

使用Typhoon和Swift,我正在设置我的项目,我遇到了这个问题。我有这样的课程TPLAddInteractor

class TPLAddInteractor: NSObject, TPLAddInteractorInput {

    var output: TPLAddInteractorOutput?
    var dataManager: TPLDataManagerInterface?
}

我的装配看起来像这样

class TPLAddAssembly: TyphoonAssembly {

    var applicationAssembly: TPLApplicationAssembly?

    dynamic func addInteractor() -> AnyObject {

        return TyphoonDefinition.withClass(TPLAddInteractor.self) {
            (definition) in

            definition.injectProperty("output", with: self.addPresenter())
            definition.injectProperty("dataManager", with: self.applicationAssembly?.dataManager())
        }
    }

    dynamic func addPresenter() -> AnyObject {

        return TyphoonDefinition.withClass(TPLAddPresenter.self) {
            (definition) in

            definition.injectProperty("interactor", with: self.addInteractor())
        }
    }
}

然后我在运行应用程序后立即收到此错误:

reason: 'Can't inject property 'dataManager' for object '<TPL.TPLAddInteractor: 0x7ff5b2d2bcf0>'. Setter selector not found. Make sure that property exists and writable'

我正在阅读Typhoon的Swift示例,我的代码中没有看到任何异常。但我是Swift的新手,所以也许我错过了一些东西。

由于

2 个答案:

答案 0 :(得分:4)

要与Typhoon合作,Swift协议必须拥有&#39; @ objc&#39;指示。这是因为Typhoon使用Objective-C运行时因为Swift还没有原生动态。

此要求记录在Swift Quick Start中。

答案 1 :(得分:1)

//Inject as follows it will give a warning but its working for me:
definition?.injectProperty(Selector(("cityInfo")), with: self.coreAssembly.cityInfo())