Skip to content

Instantly share code, notes, and snippets.

View JaNd3r's full-sized avatar
👷‍♂️
Building nice things.

Christian JaNd3r

👷‍♂️
Building nice things.
View GitHub Profile
@JaNd3r
JaNd3r / HandySnippets.swift
Last active August 29, 2015 14:25
Loosely collection of Swift snippets...
// SwingUtilities.invokeLater ;-)
func invokeLater(delay: CGFloat, code: () -> Void) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay * CGFloat(NSEC_PER_SEC))), dispatch_get_main_queue(), code)
}
// Usage:
invokeLater(0.1) {
doSomething()
}
@JaNd3r
JaNd3r / MainThreadNotification.swift
Last active December 10, 2018 05:12
Attention when moving asynchronously UI-changing code to a background thread: Notifications sent using the `NSNotificationCenter.defaultCenter()` must be sent on the main thread. Otherwise you will receive a warning like this: "This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and w…
func postMainThreadNotificationName(name: String, object: AnyObject?, userInfo: [NSObject : AnyObject]?) {
dispatch_async(dispatch_get_main_queue(), {
NSNotificationCenter.defaultCenter().postNotificationName(name, object: object, userInfo: userInfo)
})
}
@JaNd3r
JaNd3r / FirstToUpper.swift
Last active August 2, 2016 10:53
String extension which adds a function that returns the string with only its first character capitalized.
extension String {
func firstToUpper() -> String {
return self.isEmpty ? "" : String(self.characters.first!).uppercaseString + String(self.characters.dropFirst()).lowercaseString
}
}