For our project we always used one source file for both platforms: iOS and macOS (previously OS X). Right now I am migrating to Swift. Unfortunately there is some files which need
import Cocoa
and on iOS
import UIKit
previously we did
#ifdef __MAC_OS_X_VERSION_MAX_ALLOWED
#import <Cocoa/Cocoa.h>
#else
#import <UIKit/UIKit.h>
#endif
How can this be done in Swift? I don't like to write each class twice just because there is no macros anymore.
Note: On OSX Yosemite and Xcode 6.1 and above you can run the Swift Compiler by just typing swiftc in the command line. The Swift Compiler is what compiles your Swift code to binary, and it's called swiftc. Now compile and run hello. swift.
Use:
#if os(OSX)
import Cocoa
#elseif os(iOS)
import UIKit
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With