Skip to content

Instantly share code, notes, and snippets.

extension DateFormatter {
/*
DateFormatters are notoriously slow to create, so it's best to share them.
However, they're not thread safe, so this returns one DateFormatter per thread.
*/
static var shared : DateFormatter {
let key = "com.relium.swift.DateFormatter"
if let f1 = Thread.current.threadDictionary[key] as? DateFormatter {
return f1
}
@EricShapiro
EricShapiro / Avoid Storyboards
Last active February 2, 2019 16:44
Reasons to create UI in code rather than storyboard
Reasons to create UIs in code rather than Storyboards:
Merge conflicts
Easier to diff revisions and see changes in code
More flexibility to move UI elements on iPad vs iPhone,
portrait vs landscape
Easier theme support