liuwin7 liuwin7 - 11 months ago 103
Objective-C Question

Call Swift APIs in Objective-C File

In Swift, I extend the class "Date" to add one method named "swiftDate" used to print it self. May I use the method "swiftDate" like

[dateObject swiftDate]
in Objective-C environment?

Answer

Today, I look up the Apple Developer Reference and find that the Date is a Class declared in Swift, instead of Objective-C. So, I can not only use it in Objective-C, not to mention using the extended methods in Swift.

Maybe, I should extend its ReferenceType----NSDate. The classes that conform the protocol ReferenceConvertible have a typealias ReferenceType. For Date, its ReferenceType is NSDate.

You can look up the link to learn more about ReferenceConvertible.