【问题标题】:swift 4.0 dispatch_semaphore_wait with DISPATCH_TIME_FOREVERswift 4.0 dispatch_semaphore_wait 与 DISPATCH_TIME_FOREVER
【发布时间】:2018-01-24 04:56:28
【问题描述】:
dispatch_semaphore_wait(writeSemaphore!, DISPATCH_TIME_FOREVER) 

给出 DISPATCH_TIME_FOREVER 的错误,即

Cannot convert value of type 'Int' to expected argument type 'dispatch_time_t' (aka 'UInt64') 

Een 赋值 DispatchTime.distantFuture 无济于事。

谁能告诉我dispatch_time_t(超时)的值是多少

【问题讨论】:

  • dispatch_semaphore_wait 是一个 Swift 2 API。在 Swift 3 及更高版本中使用 DispatchSemaphore

标签: swift grand-central-dispatch semaphore swift4


【解决方案1】:

我会去:

    writeSemaphore!.wait(timeout: .distantFuture)

但是你应该改进你的代码,确保你的可选项不为零。如下寻找守卫:

    guard let writeSemaphore = writeSemaphore else { return }

    writeSemaphore.wait(timeout: .distantFuture)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-21
    • 2017-04-20
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多