C macros for watchOS and Swift API Availability

Introduction

Added C macros for watchOS and Swift API Availability from Xcode 7 (iOS 9.0 / OS X 10.11 / watchOS 2.0, Apple LLVM version 7.0.0 / Apple Swift version 2.0 / clang-700.0.72 / swiftlang-700.0.59) Introducing.

C macro for watchOS

TARGET_OS_WATCH

TargetConditionals.h

#define TARGET_OS_IPHONE 1 
#define TARGET_OS_IOS    0
#define TARGET_OS_WATCH  1

Defined when generating code to run on the Apple Watch (TARGET_OS_IPHONE is also 1). In the case of iOS, it is defined as follows.

#define TARGET_OS_IPHONE 1 
#define TARGET_OS_IOS    1
#define TARGET_OS_WATCH  0

__WATCHOS_1_0, __WATCHOS_2_0

Availability.h

#define __WATCHOS_1_0    10000
#define __WATCHOS_2_0    20000

Define the watchOS version number.

__WATCHOS_UNAVAILABLE, __WATCHOS_PROHIBITED

Availability.h

#define __WATCHOS_UNAVAILABLE __OS_AVAILABILITY(watchos,unavailable)
#define __WATCHOS_PROHIBITED  __OS_AVAILABILITY(watchos,unavailable)

Both define unavailability in watchOS.

__WATCHOS_AVAILABLE

Availability.h

#define __WATCHOS_AVAILABLE(_vers) __OS_AVAILABILITY(watchos,introduced=_vers)

Define that it is used from the specified version of watchOS.

__WATCHOS_DEPRECATED(_start, _dep, _msg)

Availability.h

#define __WATCHOS_DEPRECATED(_start, _dep, _msg) __WATCHOS_AVAILABLE(_start) __OS_AVAILABILITY_MSG(watchos,deprecated=_dep,_msg)

Defines that it is available from the version of watchOS specified by _start and deprecated by the version of watchOS specified by _dep. Specify a message instructing an alternative with _msg.

__WATCH_OS_VERSION_MIN_REQUIRED, __WATCH_OS_VERSION_MAX_ALLOWED

AvailabilityInternal.h

#ifndef __WATCH_OS_VERSION_MIN_REQUIRED
    #ifdef __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__
        /* compiler sets __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ when -mwatchos-version-min is used */
        #define __WATCH_OS_VERSION_MIN_REQUIRED __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__
        #define __WATCH_OS_VERSION_MAX_ALLOWED 20000
        /* for compatibility with existing code.  New code should use platform specific checks */
        #define __IPHONE_OS_VERSION_MIN_REQUIRED 90000
    #endif
#endif

Define the minimum / maximum watchOS version supported by your application. If you specify -mwatchos-version-min, the compiler sets its value to __WATCH_OS_VERSION_MIN_REQUIRED.

Swift API Availability Specify watchOS as the platform name for # available.

if #available(watchOS 2.1, ..., *) {
    ...

Recommended Posts

C macros for watchOS and Swift API Availability
C macros for tvOS and Swift API Availability
Introducing C ++ characters and strings for Swift programmers
[For beginners] About lambda expressions and Stream API
[Swift] API used for apps that passed the selection
Treat Swift functions and closures as C function pointers
Create UnsafeMutablePointer <UnsafeMutablePointer <Int8>?>! In Swift for C char ** hoge
[Swift] Use for where rather than nesting for and if