-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGobalFunctions.swift
44 lines (36 loc) · 1.04 KB
/
GobalFunctions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Foundation
/// Shortcut for NSLocalizedString with empty comment
func L(_ key: String) -> String {
return NSLocalizedString(key, comment: "")
}
/**
Run closure in background
Do not call UI on execution!
*/
func future(closure: @escaping ()->()) {
let backQueue = DispatchQueue.global()
backQueue.async(execute: closure)
}
/**
Run closure in background after delay
Do not call UI on execution!
*/
func delaiedFuture(_ delayInSeconds: Double, closure: @escaping ()->()) {
let delay = DispatchTime.now() + delayInSeconds
let backQueue = DispatchQueue.global()
backQueue.asyncAfter(deadline: delay, execute: closure)
}
/**
Run closure after delay on main thread
Safe for UI calls
*/
func delayCall(_ delayInSeconds: Double, closure: @escaping()->()) {
let delay = DispatchTime.now() + delayInSeconds
DispatchQueue.main.asyncAfter(deadline: delay) {
closure()
}
}
/// Run any closure on main thread explisitly
func ui(_ closure: @escaping ()->()){
DispatchQueue.main.async(execute: closure)
}