ios - How to to push the data to an array by delay 200ms in swift -


i use tcp socket receieve data server(about 100 times in 1 second) , when receieve data ,i want push array delay 200ms, how do?

you can use dispatch_after run closure after specified amount of time. need determine of queues closure should run on, documentation on queues , purpose here:

https://developer.apple.com/library/ios/documentation/performance/reference/gcd_libdispatch_ref/#//apple_ref/c/func/dispatch_get_global_queue

for example i'll use qos_class_utility intended long running background tasks.

let qos = int(qos_class_utility.value) let delayinmilliseconds = 200 let delay = int64(delayinmilliseconds * double(nsec_per_msec)) let dispatchtime = dispatch_time(dispatch_time_now, delay) dispatch_after(dispatchtime, dispatch_get_global_queue(qos,0)) {     //code push data array  } 

Comments