Search code examples
swift2promisekit

Can't specify the type of parameter to "then" handler


If I specifiy the type of my parameter of a then handler as so...

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

then I get the error...

Cannot convert value of type '[Thing] -> Void' to expected argument type '(AnyObject) -> AnyPromise'

Is it possible to do what I'm attempting or do I need to cast the parameter in the body of the handler?

If you look here then the Objective-C code shows setting the parameter to an NSArray, which is, at least, not any object.

.then(^(NSArray *fetchedKittens){

Solution

  • One must specify the required type using the promise's generic parameter.

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

    And its not necessary to type the parameter to the then handler.

    .then { things -> Void in