I have an Obj-C category on NSDate
and I am trying to use the functions in that category with Swift's Date structure.
Is there a clean way to do that without having to cast every time or having to create NSDate
instance from Date
or some ugly other hack?
Or am I stuck with having to define my objects as NSDate instead of Date?
Apple mentions here that
The Swift overlay to the Foundation framework provides the Date structure, which bridges to the NSDate class. The Date value type offers the same functionality as the NSDate reference type, and the two can be used interchangeably in Swift code that interacts with Objective-C APIs. This behavior is similar to how Swift bridges standard string, numeric, and collection types to their corresponding Foundation classes.
, so my question is how can I access the extra functions in my NSDate
category with my Date
objects with clean minimal code?
For reference, I am using Swift 3.
NSDate
Objective-C category, you have to cast yourDate
object toNSDate
. Or you can rewrite your category as a Swiftextension
toDate
. – Nautch