Last active
January 15, 2016 09:51
-
-
Save kakilangit/29058d187e58a0960edc to your computer and use it in GitHub Desktop.
Background Thread Reusable function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func backgroundThread(delay: Double = 0.0, background: (() -> Void)? = nil, completion: (() -> Void)? = nil) { | |
| dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)) { | |
| if(background != nil){ background!(); } | |
| let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))) | |
| dispatch_after(popTime, dispatch_get_main_queue()) { | |
| if(completion != nil){ completion!(); } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment