Search code examples
iospreprocessorwatchkitc-preprocessorwatchos-2

Preprocessor macro for Apple Watch?


I was looking at Apple's Lister (for Apple Watch, iOS, and OS X) sample. The sample performs a test for iOS and OS X:

#import <TargetConditionals.h>

#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)

@import ListerKit;

#elif TARGET_OS_MAC

@import ListerKitOSX;

#endif

However, there is no test for TARGET_OS_WATCH or similar. Grepping for watch in TargetConditionals.h delivers no hits:

$ cat /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
  /SDKs/iPhoneOS7.1.sdk/usr/include/TargetConditionals.h | grep -i watch
$

From TargetConditionals.h, I know there are:

    These conditionals specify in which Operating System the generated code will
    run. The MAC/WIN32/UNIX conditionals are mutually exclusive.  The EMBEDDED/IPHONE 
    conditionals are variants of TARGET_OS_MAC. 

        TARGET_OS_MAC           - Generate code will run under Mac OS
        TARGET_OS_WIN32         - Generate code will run under 32-bit Windows
        TARGET_OS_UNIX          - Generate code will run under some non Mac OS X unix 
        TARGET_OS_EMBEDDED      - Generate code will run under an embedded OS variant
                                  of TARGET_OS_MAC
        TARGET_OS_IPHONE        - Generate code will run under iPhone OS which 
                                  is a variant of TARGET_OS_MAC.
    TARGET_IPHONE_SIMULATOR     - Generate code for running under iPhone Simulator

Question: Is there a preprocessor for Apple's watch?


I'm tagging with , but I'm not sure that's the correct OS for this question.

The list below was compiled from iPhone's TargetConditionals.h. The Simulator and OS X are similar (they just have different bits set to 1):

#define TARGET_OS_MAC               1
#define TARGET_OS_WIN32             0
#define TARGET_OS_UNIX              0
#define TARGET_OS_EMBEDDED          1 
#define TARGET_OS_IPHONE            1 
#define TARGET_IPHONE_SIMULATOR     0 

Questions: Does the watch use TARGET_OS_EMBEDDED? Does the watch omit TARGET_OS_IPHONE?


Solution

  • As of watchOS 2.0, you can run native code on the watch, so this is a more relevant question.

    I'm using the first early beta of watchOS 2, so this may change, but right now, TARGET_OS_WATCH is set to 1 on watchOS.

    (Also, be careful: TARGET_OS_IPHONE is also set to 1 on watchOS, though TARGET_OS_IOS is 0.)