【问题标题】:PromiseKit compilation errorsPromiseKit 编译错误
【发布时间】:2020-03-30 04:55:55
【问题描述】:

我是 PromiseKit 的新手,但是我无法获得一些非常基本的工作。考虑一下:

func test1() -> Promise<Bool> {
    return Promise<Bool>.value(true)
  }

  func test2() -> Promise<Bool> {
    return Promise<Bool> { seal in
      seal.fulfill(true)
    }
  }

  func test3() -> Promise<Bool> {
    return Promise<Bool>.value(true)
  }

以下内容给了我每一行的错误:

无法将 Promise&lt;Bool&gt; 类型的值转换为闭包结果类型 Guarantee&lt;()&gt;

 firstly {
    test1()
  }.then {
    test2()
  }.then {
    test3()
  }.done {

  }.catch {

  }

我做错了什么?我一直在尝试各种组合,但似乎没有任何效果。我在PromiseKit 6.13

【问题讨论】:

    标签: swift promisekit xcode11.4


    【解决方案1】:

    来自PromiseKit疑难解答guide

    Swift 不允许你默默地忽略闭包的参数。

    所以你只需要specify 闭包参数,如下所示:

    firstly {
            test1()
        }.then { boolValue in
            self.test2()
        }.then { boolValue in
            self.test3()
        }.done { _ in
    
        }.catch { _ in
    
        }
    

    甚至将_ 名称分配给参数(确认参数存在但忽略其名称)

    firstly {
            test1()
        }.then { _ in
            self.test2()
        }.then { _ in
            self.test3()
        }.done { _ in
    
        }.catch { _ in
    
        }
    

    【讨论】:

    • 谢谢!我最终在查看文档后弄明白了,当他们说 Swift 编译器可能会向您抛出虚假错误时,我可以明白他们的意思。啊。令人沮丧的是它没有显示更有意义的编译器错误。不敢相信我最终在如此明显的事情上浪费了这么多时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 2011-09-04
    相关资源
    最近更新 更多