TARGET_OS_IOS in WatchKit Extension

Hi,


I'm trying to use #ifdef TARGET_OS_IOS to have a part of an UIImage extension not to be compiled if used (included) in a WatchKit Extension. But it doesn't seem to work since I get a compilation error inside the ifdefed block.


Dirk

For WatchKit 1 extensions, TARGET_OS_IOS returns true because the extension is compiled for, and runs on, the iPhone. You're best option is to define a custom macro in the build settings for the WatchKit extension and conditionally compile based on that:


#ifndef MY_MACRO_THATS_ONLY_DEFINED_FOR_THE_WATCHKIT_EXTENSION
...
#endif

Thanks for you're reply but it's a WatchOS 2 WatchKit Extension, so I expected TARGET_OS_WATCH to be true. Anyway, it turns out I didn't need this particular class extension. 🙂


Dirk

Side note: you are using #ifdef, apple now always defines the value as 0 or 1 in the targetconditionals.h file. You should check '#if' without the 'def' part

TARGET_OS_IOS in WatchKit Extension
 
 
Q