Swift 如何使用promiseKit中返回值的方法

Swift 如何使用promiseKit中返回值的方法,swift,promisekit,Swift,Promisekit,我创建了一组承诺,这些承诺依赖于可能抛出错误的函数的结果。我可以像下面的代码所示让它工作,但是我不喜欢双捕获块。我想使用单个promiseKit捕捉块。有没有更好的解决方案 do { let accounts = try Account.getAccounts() let mailboxPromises = accounts.map { self.fetchMailboxes($0) } when(fulfilled: mailboxPromises).map { _

我创建了一组承诺,这些承诺依赖于可能抛出错误的函数的结果。我可以像下面的代码所示让它工作,但是我不喜欢双捕获块。我想使用单个promiseKit捕捉块。有没有更好的解决方案

do {
    let accounts = try Account.getAccounts()
    let mailboxPromises = accounts.map { self.fetchMailboxes($0) }

    when(fulfilled: mailboxPromises).map { _ in
        self.updateBadgeCount()
    }
    .catch { (error) in

    }
} catch  {

}

也许将Account.getAccounts()包装成一个承诺,然后在承诺链中使用

func getAccounts() -> Promise<[Account]> {
    return Promise {
        do {
            let accounts = try Account.getAccounts()
            $0.fulfill(accounts)
        } catch {
            $0.reject(error)
        }
    }
}

在then或done中使用try可以起作用,但在First中不起作用,这正是我需要使用它的地方。您建议的第一个解决方案似乎是唯一有效的解决方案,但它实际上并不会产生一个不那么复杂的解决方案。
foo().then { baz in
    bar(baz)
}.then { result in
    try doOtherThing()
}.catch { error in
    // if doOtherThing() throws, we end up here
}