【问题标题】:Can't specify the type of parameter to "then" handler无法为“then”处理程序指定参数类型
【发布时间】:2015-10-28 15:06:59
【问题描述】:

如果我这样指定then 处理程序的参数类型...

.then { (things: [Thing]) -> Void in

然后我得到错误...

无法将“[Thing] -> Void”类型的值转换为预期参数 输入'(AnyObject) -> AnyPromise'

是否可以做我正在尝试的事情,或者我是否需要在处理程序的主体中强制转换参数?

如果您查看here,那么 Objective-C 代码显示将参数设置为 NSArray,至少不是任何对象。

.then(^(NSArray *fetchedKittens){

【问题讨论】:

    标签: swift2 promisekit


    【解决方案1】:

    必须使用 promise 的泛型参数指定所需的类型。

    public func MyAsyncFunction() -> Promise<[Thing]>
    

    并且没有必要将参数键入then 处理程序。

    .then { things -> Void in
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-28
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      • 2012-05-27
      相关资源
      最近更新 更多