I have a problem with all my categories written for NSDate, NSString ... The Migration to Swift 3 did change now all NSDate properties to Date (in swift files). Now I cannot call my NSDate+Additions category methods from properties of Date type in Swift.
So for example I have this category in Obj C
@interface NSDate (Additions)
- (BOOL)isTimedOut;
@end
And I have swift file containing:
let date: Date = Date.init()
let isTimedOut = date.isTimedOut()
Until now I come up with two solutions:
First is to cast so it would be
let isTimedOut = (date as NSDate).isTimedOut()
Another solution is to create Date extension with all method and call from each method the obj C methods.
I would like to know if there is a way to say somehow to the compiler to auto generate swift Date extension (not NSDate). Like:
@interface NSDate (KDApi) NS_SWIFT_NAME(Date);
I tried it and it did not work.
This is the intended behavior from swift 3.0. Developers from Apple confirmed that NSDate and Date are two different types. Also, categories from NSDate to Date extensions are not bridged, unlike the case of NSString and String, which is yes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.