How do I write universal swift code for both iOS and OS X. In cocoa I could use #ifdef, what do I do now?
for our project we always used one source file for both platforms: iOS and OS X. Right now I am migrating to swift. Unfortunately there is some files which need
and on iOS
previously we did
#ifdef __MAC_OS_X_VERSION_MAX_ALLOWED #import <Cocoa/Cocoa.h> #else #import <UIKit/UIKit.h> #endif
Do you know how this can be done in swift? I don’t like to write each class twice just because there is no macros anymore.
Thanks in advance
- When compiling for multiple targets in XCode, how do i ensure that certain files will not be included one target
- Conditional Compilation - Check Scheme
- Swift: iOS Deployment Target Command Line Flag
- Which conditional compile to use to switch between Mac and iPhone specific code?
- What #defines are set up by Xcode when compiling for iPhone
- Conditional compilation when using ARC
Solutions Collect From Internet About “How do I write universal swift code for both iOS and OS X. In cocoa I could use #ifdef, what do I do now?”
#if os(OSX) import Cocoa #elseif os(iOS) import UIKit #endif
- How can we create a generic Array Extension that sums Number types in Swift?
- ARC – The meaning of __unsafe_unretained?
- voice over can only see a page of a uicollectionview
- Listen for window resize event in Swift / Objective-C
- Why does NSObject's “isMemberOfClass:class” specify __unsafe_unretained in XCode's autocompletion?
- Is possible to change the price of an In App purchase after the Application is approved?
- glReadPixels doesn't read depth buffer values on iOS
- What is the '^' in Objective-C
- about showing continuous slider value in UISlider
- Toggling AirPlane mode in iOS Programmatically
- Using UIPopoverBackgroundView class
- iOS5: willSendRequestForAuthenticationChallenge method is running recursive
- CLLocationManager requestWhenInUseAuthorization() not working
- edgesForExtendedLayout ignored on iOS9 when using custom animation
- How to load .dll file which returns assembly in Objective-C?