Reputation: 945
I'm building a module that will be used in a iOS/OSX app.
The client is insisting that the module work on both iOS and OSX.
I need to check the system version which I'm doing with UIDevice on iOS and on OSX I'm using FTWDevice.
The problem is that when I try to compile it on OSX it complains that OSX doesn't support UIDevice.
I'm wondering if there is a way I can tell the compiler to compile a line of code on iOS but not on OSX?
I know I can do this with this to compile something on production only:
#ifndef DEBUG
[Crashlytics startWithAPIKey:CRASHLYTICSKEY];
#endif
Is there a solution for this or should I tell the client they're gonna need 2 modules that are exactly the same except for one line?
Another acceptable solution would be a workaround for finding the system version on iOS that doesn't involve using UIDevice.
Upvotes: 1
Views: 130
Reputation: 236370
Another acceptable solution would be a workaround for finding the system version on iOS that doesn't involve using UIDevice.
You can do as follow to obtain system version (OS X and iOS):
func majorVersion() -> Int { return NSProcessInfo.processInfo().operatingSystemVersion.majorVersion }
func minorVersion() -> Int { return NSProcessInfo.processInfo().operatingSystemVersion.minorVersion }
func patchVersion() -> Int { return NSProcessInfo.processInfo().operatingSystemVersion.patchVersion }
func myOSVersion() -> String { return NSProcessInfo.processInfo().operatingSystemVersionString }
Upvotes: 1
Reputation: 9768
Look at TargetConditionals.h
. Specifically:
#if TARGET_OS_MAC
// Mac-only code here
#endif
#if TARGET_OS_IPHONE
// iOS-only code here
#endif
Upvotes: 2