swiftpromisekitxcode11.4

PromiseKit compilation errors


I'm new to PromiseKit however I can't get something very basic to work. Consider this:

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)
  }

The following gives me the error on each line:

Cannot convert value of type Promise<Bool> to closure result type Guarantee<()>

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

  }.catch {

  }

What am I doing wrong? I've been trying various combinations but nothing seems to work. I'm on PromiseKit 6.13.


Solution

  • From the PromiseKit troubleshooting guide:

    Swift does not permit you to silently ignore a closure's parameters.

    So you have to just specify closure parameter like below:

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

    or even with assigning the _ name to the parameter (acknowledge argument existence but ignoring its name)

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