swift - 从何时捕获进度

标签 swift promisekit

我的 Promise 用法看起来像 -

when(fulfilled: [promise]).then {(response) -> Void in


}.catch { (error) in
    print(error)
}

我正在尝试找出如何利用 when.swift 中的 progress 属性,但到目前为止还没有成功。提前致谢。 enter image description here

最佳答案

PromiseKit 本身就有一个例子:

https://github.com/mxcl/PromiseKit/blob/master/Tests/CorePromise/03_WhenTests.swift#L120-L141

func testProgress() {
    let ex = expectation(description: "")

    XCTAssertNil(Progress.current())

    let p1 = after(.milliseconds(10))
    let p2 = after(.milliseconds(20))
    let p3 = after(.milliseconds(30))
    let p4 = after(.milliseconds(40))

    let progress = Progress(totalUnitCount: 1)
    progress.becomeCurrent(withPendingUnitCount: 1)

    when(fulfilled: p1, p2, p3, p4).done { _ in
        XCTAssertEqual(progress.completedUnitCount, 1)
        ex.fulfill()
    }

    progress.resignCurrent()

    waitForExpectations(timeout: 1, handler: nil)
}

关于swift - 从何时捕获进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47041579/

相关文章:

ios - swift : UIPanGestureRecognizer delegate method not called

ios - 如何使用 swift-4 Promises then, done, catch 等 block

swift - 如何利用 PromiseKit 确保在继续之前检索到查询的对象?

ios - UIScreenEdgePanGestureRecognizer

json - 打开应用程序时如何加载数据?

ios - 用条纹填充 UIBezierPath 形状

ios - Swift - didReceiveRemoteNotification - PromiseKit

ios - Swift - 带循环的多个链 http 请求

swift - 我如何在循环中链接 Swift 中的 promise ?

swift - 在 Swift 3 中保存日期组件