Promisekit: Return empty Promise for next ".then" or ".catch" closures

Created on 17 Apr 2017  路  3Comments  路  Source: mxcl/PromiseKit

  • PromiseKit version: PromiseKit (4.1.7)
  • Xcode version: Xcode 8.3.1
  • CocoaPods version: PromiseKit (4.1.7)

Hello! I think this is noob question. I am straining to using PromiseKit. So my question is how I can return empty Promise object? For example my current worked code is

        EventsWorker.getAllEvents().then { events in
            self.events = events
        }.then {
            fulfill()
        }.catch { error in
            reject(error)
        }

I want this to modify as:

       EventsWorker.getAllEvents().then { events in
            self.events = events
            fulfill()
            // I must return Promise<T> here, right?
        }.catch { error in
            reject(error)
        }

Thank you in advance!

Most helpful comment

// I must return Promise here, right?

No, you can return Void. I presume you are getting an error, although you didn't say. If so specify the return type:

  EventsWorker.getAllEvents().then { events -> Void in

All 3 comments

// I must return Promise here, right?

No, you can return Void. I presume you are getting an error, although you didn't say. If so specify the return type:

  EventsWorker.getAllEvents().then { events -> Void in

Thank you @mxcl , that's what I need!
Yes, my error was "Missing return in a closure expected to return 'Promise<()>'"

np, this is an unfortunately common problem, and there's nothing we can do, it's up to the Swift team to fix it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zvonicek picture zvonicek  路  3Comments

adrianbg picture adrianbg  路  6Comments

victoraraujo01 picture victoraraujo01  路  3Comments

daanporon picture daanporon  路  6Comments

emreond picture emreond  路  5Comments