swift 1.2 上的 RACCommand 编译失败
RACCommand compilation failure on swift 1.2
我有一个登录按钮,分配了一个 RACCommand 来执行登录请求,return 我是一个用户对象。
我想处理来自按钮信号错误的错误。
loginButton.rac_command.executionSignals.flatten()
.logAll()
.subscribeNext { (_:AnyObject!) -> Void in
println("Sent next")
}
所以我在 subscribeNext 块之前添加了 doError 块,但现在代码无法编译:
loginButton.rac_command.executionSignals.flatten()
.logAll()
.doError { (err:NSError) -> Void in
println(err.description)
}
.subscribeNext { (_:AnyObject!) -> Void in
println("Sent next")
}
现在返回错误:
cannot invoke 'subscribeNext' with an argument list of type '(AnyObject! -> Void)'
因为 doError 的签名是:
- (RACSignal *)doError:(void (^)(NSError *error))block;
我假设它返回给我的信号与传递给 doError 块的信号相同,因此我可以订阅它。
不知道为什么这根本无法编译。
非常感谢对此问题的任何见解。
doError()
的参数中有拼写错误(编译器错误识别):它应该是 (NSError!) -> Void
类型而不是 (NSError) -> Void
。像这样修改它可以正常编译:
loginButton.rac_command.executionSignals.flatten()
.logAll()
.doError { (err:NSError!) -> Void in
println(err.description)
}
.subscribeNext { (_:AnyObject!) -> Void in
println("Sent next")
}
补充说明
- 来自
RACCommand
的错误被内部捕获并在 errors()
上发送
信号,所以 none 在 executionSignals()
信号上发送。
doNext()
、doError()
、doComplete()
方法用于
向信号注入副作用。所以你通常在使用它们时
创建信号,而不是在处理其事件时。你可能想使用
subscribeNext(nextBlock:error:completed:)
方法(或其一种方便的形式)代替。
我有一个登录按钮,分配了一个 RACCommand 来执行登录请求,return 我是一个用户对象。
我想处理来自按钮信号错误的错误。
loginButton.rac_command.executionSignals.flatten()
.logAll()
.subscribeNext { (_:AnyObject!) -> Void in
println("Sent next")
}
所以我在 subscribeNext 块之前添加了 doError 块,但现在代码无法编译:
loginButton.rac_command.executionSignals.flatten()
.logAll()
.doError { (err:NSError) -> Void in
println(err.description)
}
.subscribeNext { (_:AnyObject!) -> Void in
println("Sent next")
}
现在返回错误:
cannot invoke 'subscribeNext' with an argument list of type '(AnyObject! -> Void)'
因为 doError 的签名是:
- (RACSignal *)doError:(void (^)(NSError *error))block;
我假设它返回给我的信号与传递给 doError 块的信号相同,因此我可以订阅它。
不知道为什么这根本无法编译。 非常感谢对此问题的任何见解。
doError()
的参数中有拼写错误(编译器错误识别):它应该是 (NSError!) -> Void
类型而不是 (NSError) -> Void
。像这样修改它可以正常编译:
loginButton.rac_command.executionSignals.flatten()
.logAll()
.doError { (err:NSError!) -> Void in
println(err.description)
}
.subscribeNext { (_:AnyObject!) -> Void in
println("Sent next")
}
补充说明
- 来自
RACCommand
的错误被内部捕获并在errors()
上发送 信号,所以 none 在executionSignals()
信号上发送。 doNext()
、doError()
、doComplete()
方法用于 向信号注入副作用。所以你通常在使用它们时 创建信号,而不是在处理其事件时。你可能想使用subscribeNext(nextBlock:error:completed:)
方法(或其一种方便的形式)代替。