C macros for tvOS and Swift API Availability

Introduction

With C macros for tvOS added from Xcode 7.1 (iOS 9.1 / OS X 10.11 / watchOS 2.0 / tvOS 9.0, Apple LLVM version 7.0.0 / Apple Swift version 2.1 / clang-700.1.76 / swiftlang-700.1.101.6) Introducing Swift API Availability.

C macro for tvOS

TARGET_OS_TV

TargetConditionals.h

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

Defined when generating code to run on Apple TV (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
#define TARGET_OS_TV                0

__TVOS_9_0

Availability.h

#define __TVOS_9_0       90000

Define the tvOS version number.

__TVOS_UNAVAILABLE, __TVOS_PROHIBITED

Availability.h

#define __TVOS_UNAVAILABLE __OS_AVAILABILITY(tvos,unavailable)
#define __TVOS_PROHIBITED  __OS_AVAILABILITY(tvos,unavailable)

Both define unavailable on tvOS.

__TVOS_AVAILABLE

Availability.h

#define __TVOS_AVAILABLE(_vers) __OS_AVAILABILITY(tvos,introduced=_vers)

Define that it is available from the specified version of tvOS.

__TVOS_DEPRECATED(_start, _dep, _msg)

Availability.h

#define __TVOS_DEPRECATED(_start, _dep, _msg) __TVOS_AVAILABLE(_start) __OS_AVAILABILITY_MSG(tvos,deprecated=_dep,_msg)

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

__TV_OS_VERSION_MIN_REQUIRED, __TV_OS_VERSION_MAX_ALLOWED

AvailabilityInternal.h

#ifndef __TV_OS_VERSION_MIN_REQUIRED
    #ifdef __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__
        /* compiler sets __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ when -mtvos-version-min is used */
        #define __TV_OS_VERSION_MIN_REQUIRED __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__
        #define __TV_OS_VERSION_MAX_ALLOWED __IPHONE_9_0
        /* 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 tvOS version supported by your application. If you specify -mtvos-version-min, the compiler sets its value to __TV_OS_VERSION_MIN_REQUIRED.

Swift API Availability

Specify tvOS as the platform name of # available.

if #available(tvOS 9.1, ..., *) {
    ...

Recommended Posts

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