If this is true , the actual code will replace all the code with
lazy var dateFormatter : NSDateFormatter = { let formatter = NSDateFormatter() formatter.dateStyle = .MediumStyle formatter.timeStyle = .MediumStyle return formatter }()
This variable is lazily initialized once the first time it is accessed.
Edit: You can also declare a variable a constant without a lazy attribute.
let dateFormatter : NSDateFormatter = { ...
The difference is that formatting is created immediately ( not lazily) during instance initialization.
Edit:
In Swift 3, NSDateFormatter been renamed DateFormatter
and .MediumStyle to .MediumStyle
source share