[swift-users] Swift Version Conditionals in Objective-C?

Jon Shier jon at jonshier.com
Fri Sep 22 13:18:07 CDT 2017


	In moving a hybrid project from Swift 3 to 4, I’ve run into some issues from my Objective-C code. I’ve been able to conditionalize my Swift code for both versions pretty easily, but there are APIs imported from Objective-C that need to change definition for Swift 4. Is there anyway, in preprocessor or at runtime, to detect what version of Swift the Objective-C is being imported into? It’s as simple as a typedef for NSAttributedString attributes dictionaries that needs a different generic type in Swift 3 vs. Swift 4. Browsing the documentation I don’t see anything, but I’m guess some such method exists, given Apple’s APIs can do so. This would only be a temporary situation until the move the Swift 4 can be completed.



Jon Shier


More information about the swift-users mailing list