Skip to content

Instantly share code, notes, and snippets.

@u10int
Forked from calebd/ArrayHelpers.swift
Created June 12, 2014 01:13
Show Gist options
  • Save u10int/23d66c9235de922c83d4 to your computer and use it in GitHub Desktop.
Save u10int/23d66c9235de922c83d4 to your computer and use it in GitHub Desktop.
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
if isEmpty {
return nil
}
let index = count - 1
return self[index]
}
}
let offset = 2.0
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(offset * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), {
// Do something
})
class func sharedClient() -> CanaryClient {
struct Static {
static var instance: CanaryClient?
static var token: dispatch_once_t = 0
}
dispatch_once(&Static.token, {
Static.instance = CanaryClient()
})
return Static.instance!
}
// You can make aliases for closure types
typealias AccountStoreMultipleAccountsCompletion = (ACAccount[]?, NSError?) -> ()
typealias AccountStoreSingleAccountCompletion = (ACAccount?, NSError?) -> ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment