Karamjeet Singh
Karamjeet Singh

Reputation: 490

swift 4.0 dispatch_semaphore_wait with DISPATCH_TIME_FOREVER

dispatch_semaphore_wait(writeSemaphore!, DISPATCH_TIME_FOREVER) 

gives error for DISPATCH_TIME_FOREVER i.e.

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

Een assigning a value DispatchTime.distantFuture could not help.

Can any one let me know what could be the value of dispatch_time_t(timeout)

Upvotes: 1

Views: 1822

Answers (1)

Stéphane de Luca
Stéphane de Luca

Reputation: 13583

I'll go for:

    writeSemaphore!.wait(timeout: .distantFuture)

But you should improve you code, by making sure your optional isn't nil. Go for a guard as follows:

    guard let writeSemaphore = writeSemaphore else { return }

    writeSemaphore.wait(timeout: .distantFuture)

Upvotes: 1

Related Questions