My NSDate + Api category no longer works for the Date class in Swift (after migrating to Swift 3 and Swift Interoperability)

I have a problem with all my categories written for NSDate, NSString ... Migration to Swift 3 has now changed all NSDate properties to Date (in fast files). Now I can’t call NSDate + Additions category methods from Date type properties in Swift.

So for example, I have this category in Obj C

@interface NSDate (Additions)

- (BOOL)isTimedOut;

@end

And I have a quick file containing:

let date: Date = Date.init()
let isTimedOut = date.isTimedOut()

So far I have come up with two solutions:

First is to cast so it would be 
let isTimedOut = (date as NSDate).isTimedOut()

Another solution is to create a date extension with the whole method and call obj C methods from each method.

I would like to know if there is a way to tell the compiler in some way to automatically generate a quick date extension (not NSDate). How:

@interface NSDate (KDApi) NS_SWIFT_NAME(Date);

I tried and it didn't work.

+4
1

swift 3.0. Apple , NSDate Date . , NSDate to Date , NSString String, .

+2

Source: https://habr.com/ru/post/1655206/


All Articles