-
-
Save Chris-Gillis/9fee69b9dda54796ccde to your computer and use it in GitHub Desktop.
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
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] | |
} | |
func tail() -> T[] { | |
if self.isEmpty || self.count == 1 { | |
return Array() | |
} | |
return self.subArray(NSRangeFromString("{1, \(self.count - 1)")) | |
} | |
func subArray(range : NSRange) -> T[]{ | |
var newArray = Array() | |
for i in range.location...range.length { | |
newArray += self[i] | |
} | |
return newArray | |
} | |
} |
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
let offset = 2.0 | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(offset * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { | |
// Do something | |
}) |
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
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! | |
} |
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
// 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