dispatch-after

How to program a delay in Swift 3

家住魔仙堡 提交于 2019-11-26 05:59:00
问题 In earlier versions of Swift, one could create a delay with the following code: let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), 4 * Int64(NSEC_PER_SEC)) dispatch_after(time, dispatch_get_main_queue()) { //put your code which should be executed with a delay here } But now, in Swift 3, Xcode automatically changes 6 different things but then the following error appears: \"Cannot convert DispatchTime.now to expected value dispatch_time_t aka UInt64 .\" How can one create a delay

How to create dispatch queue in Swift 3

谁都会走 提交于 2019-11-25 23:45:28
问题 In Swift 2, I was able to create queue with the following code: let concurrentQueue = dispatch_queue_create(\"com.swift3.imageQueue\", DISPATCH_QUEUE_CONCURRENT) But this doesn\'t compile in Swift 3. What is the preferred way to write this in Swift 3? 回答1: Creating a concurrent queue let concurrentQueue = DispatchQueue(label: "queuename", attributes: .concurrent) concurrentQueue.sync { } Create a serial queue let serialQueue = DispatchQueue(label: "queuename") serialQueue.sync { } Get main