我有代表登录用户的类
public class User: NSObject {
init(authenticator: Authenticator) {
self.authenticator = authenticator
}
...
}
它唯一的初始参数是符合Authenticator 协议的对象
protocol Authenticator
{
func authenticate(login:String , password:String , handler: (result:AuthenticationResult)->() )
}
在我的例子中,Auth 对象是类BackendService的实例
我的台风大会定义是:
public dynamic func user() -> AnyObject {
return TyphoonDefinition.withClass(User.self) {
(definition) in
definition.useInitializer("initWithAuthenticator") {
(initializer) in
initializer.injectParameterWith( self.backendService() )
}
}
}
应用程序导致运行时错误
'Method 'initWithAuthenticator' has 0 parameters, but 1 was injected. Do you mean 'initWithAuthenticator:'?'
如果我将 init 方法更改为 'initWithAuthenticator:' 它会崩溃
'Method 'initWithAuthenticator:' not found on 'PersonalMessages.User'. Did you include the required ':' characters to signify arguments?'