Skip to content

Instantly share code, notes, and snippets.

@TheDarkCode
Created June 22, 2016 08:09
Show Gist options
  • Save TheDarkCode/6170f8c185c5aeaead70ee14d64ec840 to your computer and use it in GitHub Desktop.
Save TheDarkCode/6170f8c185c5aeaead70ee14d64ec840 to your computer and use it in GitHub Desktop.
Delay Utility for GCD in Swift 3
//
// Delay.swift
// Delay Utility for GCD in Swift 3
//
// Created by Mark Hamilton on 6/21/16.
// Copyright © 2016 dryverless. All rights reserved.
//
/*
example:
delay(2) {
// do after 2 seconds
}
*/
public func delay(_ delay: Double, closure:(() -> Void)) {
// var dispatchTime: DispatchTime = DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
// DispatchQueue.main.after(when: dispatchTime, execute: closure)
DispatchQueue.main.after(when: .now() + delay, execute: closure)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment