-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathUtils.swift
More file actions
34 lines (28 loc) · 867 Bytes
/
Utils.swift
File metadata and controls
34 lines (28 loc) · 867 Bytes
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
//
// Utils.swift
// SYNQueueDemo
//
import Foundation
import SYNQueue
func arrayMax<T: Comparable>(array: [T]) -> T? {
return array.reduce(array.first) { return $0 > $1 ? $0 : $1 }
}
func findIndex<T: Equatable>(array: [T], _ valueToFind: T) -> Int? {
for (index, value) in array.enumerate() {
if value == valueToFind {
return index
}
}
return nil
}
func runOnMainThread(callback:dispatch_block_t) {
dispatch_async(dispatch_get_main_queue(), callback)
}
func runOnMainThreadAfterDelay(delay:Double, _ callback:()->()) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { () -> Void in
callback()
})
}
func error(msg: String) -> NSError {
return NSError(domain: "Error", code: -1, userInfo: [NSLocalizedDescriptionKey: msg])
}