NSDate() vs NSDate.date() in Swift

[NSDate date] is a factory method for constructing an NSDate object.

If you read the guide “Using Swift with Cocoa and Objective-C”, there is a section on interacting with Objective-C apis:

For consistency and simplicity, Objective-C factory methods get mapped as convenience initializers in Swift. This mapping allows them to be used with the same concise, clear syntax as initializers.”

Excerpt From: Apple Inc. “Using Swift with Cocoa and Objective-C.” iBooks. https://itun.es/gb/1u3-0.l

So the factory method:

[NSDate date]

is converted into an initializer in Swift

NSDate()

It’s not just NSDate where you will find this pattern, but in other Cocoa API’s with factory methods.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)