Dispatch After Time using DispatchQueue


Swift Code Snippet

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  // your code here
}

Objective-C Code Snippet

var dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC)))
dispatch_after(dispatchTime, dispatch_get_main_queue(), {
  // your function here
})

Example

func fetchStockData(_ handler: @escaping (([Stock]) -> Void)) {
	DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
		let stocks = StockManagerSDK.stockData()
		handler(stocks)
    }
}