【问题标题】:Join failing in PromiseKit 3.0在 PromiseKit 3.0 中加入失败
【发布时间】:2015-11-03 21:06:52
【问题描述】:

我有一系列的承诺,我需要解决它们并列出成功的承诺。据我了解,我需要使用 join 来做到这一点。但是,当我写:

let promises: [Promise<Request>] = /* ... */
let foo = join(promises)

我收到编译时错误Cannot invoke 'join' with argument list of type '([Promise&lt;Request&gt;])'

是我做错了什么,还是 join 不能在 Swift 中工作?

【问题讨论】:

    标签: swift promisekit


    【解决方案1】:

    由于这个问题得到了投票,我想我应该发布我的最终解决方案。

    首先,使用数组调用join 是通过从http://www.drivenbycode.com/the-missing-apply-function-in-swift/ 实现apply 函数来完成的

    func apply<T, U>(fn: (T...) -> U, args: [T]) -> U {
        typealias FunctionType = [T] -> U
        return unsafeBitCast(fn, FunctionType.self)(args)
    }
    

    其次,事实证明 join 无论如何都没有做我需要的事情。我最终编写了自己的函数,我称之为anyCollect array of successful promises

    【讨论】:

      猜你喜欢
      • 2016-09-11
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-12
      • 2015-06-04
      相关资源
      最近更新 更多