Last active
December 2, 2017 19:45
-
-
Save BasThomas/9b95956c991e2c2c23c94715fab027f4 to your computer and use it in GitHub Desktop.
This file contains 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
import UIKit | |
class VC: UIViewController { | |
func formatter() -> DateFormatter { | |
struct Formatter { | |
static let f: DateFormatter = { | |
let f = DateFormatter() | |
f.dateStyle = .medium | |
print("I am called just once") | |
return f | |
}() | |
} | |
return Formatter.f | |
} | |
} | |
VC().formatter() === VC().formatter() // true, and printing just once. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment