Promisekit: Swift 4 compile error with Promise<Void>

Created on 18 Jan 2018  路  4Comments  路  Source: mxcl/PromiseKit

  • PromiseKit version: 4.5.0
  • Xcode version: 9.2
  • CocoaPods version: 1.3.1

How do you call fulfill() with a Void promise? I've looked high and low in the docs and the open/closed issues and couldn't find the answer.

Example code:

    func test1() -> Promise<String> {
        return Promise<String> { fulfill, reject in
            fulfill("Hello")
        }
    }

    func test2() -> Promise<Void> {
        return Promise<Void> { fulfill, reject in
            fulfill()
        }
    }

test1() compiles fine

test2() does not compile with this error:

fulfill()
Expression type '(_) -> Void' is ambiguous without more context

Most helpful comment

Try to return fulfill(()) for Promise<Void> statement.

All 4 comments

Try to return fulfill(()) for Promise<Void> statement.

Yes, fulfill(()). This is not an issue specific to PromiseKit (it is in fact an issue with Swift 4), there are actually maybe 4 or 5 closed issues that ask this question and there are maybe 40 or 50 examples of fulfilling Void promises here on GitHub in the PromiseKit sources, but I will add it to our TroubleShooting documentation.

I actually looked through the closed tickets and code as well but I guess my searching foo isn't so good. Thank you so much. It's frustrating to learn Swift when the syntax changes from version to version!

Changes from 3 to 4 were much less severe so hopefully 4 to 5 will be hardly anything.

Searching tickets can be hard, especially when there are so many, so it's good you opened the ticket as it made me add a proper note in the trouble-shooting guide.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

jshier picture jshier  路  4Comments

daanporon picture daanporon  路  6Comments

adrianbg picture adrianbg  路  6Comments

Banck picture Banck  路  6Comments