]>
Commit | Line | Data |
---|---|---|
6d2010ae | 1 | /* |
3e170ce0 | 2 | * Copyright (c) 2007-2015 by Apple Inc.. All rights reserved. |
6d2010ae A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | #ifndef __AVAILABILITY__ | |
25 | #define __AVAILABILITY__ | |
26 | /* | |
27 | These macros are for use in OS header files. They enable function prototypes | |
28 | and Objective-C methods to be tagged with the OS version in which they | |
29 | were first available; and, if applicable, the OS version in which they | |
30 | became deprecated. | |
31 | ||
39236c6e | 32 | The desktop Mac OS X and iOS each have different version numbers. |
6d2010ae | 33 | The __OSX_AVAILABLE_STARTING() macro allows you to specify both the desktop |
39236c6e | 34 | and iOS version numbers. For instance: |
6d2010ae A |
35 | __OSX_AVAILABLE_STARTING(__MAC_10_2,__IPHONE_2_0) |
36 | means the function/method was first available on Mac OS X 10.2 on the desktop | |
39236c6e | 37 | and first available in iOS 2.0 on the iPhone. |
6d2010ae A |
38 | |
39 | If a function is available on one platform, but not the other a _NA (not | |
40 | applicable) parameter is used. For instance: | |
41 | __OSX_AVAILABLE_STARTING(__MAC_10_3,__IPHONE_NA) | |
42 | means that the function/method was first available on Mac OS X 10.3, and it | |
43 | currently not implemented on the iPhone. | |
44 | ||
45 | At some point, a function/method may be deprecated. That means Apple | |
46 | recommends applications stop using the function, either because there is a | |
47 | better replacement or the functionality is being phased out. Deprecated | |
48 | functions/methods can be tagged with a __OSX_AVAILABLE_BUT_DEPRECATED() | |
49 | macro which specifies the OS version where the function became available | |
50 | as well as the OS version in which it became deprecated. For instance: | |
51 | __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0,__MAC_10_5,__IPHONE_NA,__IPHONE_NA) | |
52 | means that the function/method was introduced in Mac OS X 10.0, then | |
39236c6e | 53 | became deprecated beginning in Mac OS X 10.5. On iOS the function |
6d2010ae A |
54 | has never been available. |
55 | ||
56 | For these macros to function properly, a program must specify the OS version range | |
57 | it is targeting. The min OS version is specified as an option to the compiler: | |
39236c6e | 58 | -mmacosx-version-min=10.x when building for Mac OS X, and -miphoneos-version-min=y.z |
6d2010ae | 59 | when building for the iPhone. The upper bound for the OS version is rarely needed, |
39236c6e A |
60 | but it can be set on the command line via: -D__MAC_OS_X_VERSION_MAX_ALLOWED=10x0 for |
61 | Mac OS X and __IPHONE_OS_VERSION_MAX_ALLOWED = y0z00 for iOS. | |
6d2010ae A |
62 | |
63 | Examples: | |
64 | ||
65 | A function available in Mac OS X 10.5 and later, but not on the phone: | |
66 | ||
67 | extern void mymacfunc() __OSX_AVAILABLE_STARTING(__MAC_10_5,__IPHONE_NA); | |
68 | ||
69 | ||
70 | An Objective-C method in Mac OS X 10.5 and later, but not on the phone: | |
71 | ||
72 | @interface MyClass : NSObject | |
73 | -(void) mymacmethod __OSX_AVAILABLE_STARTING(__MAC_10_5,__IPHONE_NA); | |
74 | @end | |
75 | ||
76 | ||
77 | An enum available on the phone, but not available on Mac OS X: | |
78 | ||
79 | #if __IPHONE_OS_VERSION_MIN_REQUIRED | |
80 | enum { myEnum = 1 }; | |
81 | #endif | |
82 | Note: this works when targeting the Mac OS X platform because | |
83 | __IPHONE_OS_VERSION_MIN_REQUIRED is undefined which evaluates to zero. | |
84 | ||
85 | ||
86 | An enum with values added in different iPhoneOS versions: | |
87 | ||
88 | enum { | |
89 | myX = 1, // Usable on iPhoneOS 2.1 and later | |
90 | myY = 2, // Usable on iPhoneOS 3.0 and later | |
91 | myZ = 3, // Usable on iPhoneOS 3.0 and later | |
92 | ... | |
93 | Note: you do not want to use #if with enumeration values | |
94 | when a client needs to see all values at compile time | |
95 | and use runtime logic to only use the viable values. | |
96 | ||
97 | ||
98 | It is also possible to use the *_VERSION_MIN_REQUIRED in source code to make one | |
99 | source base that can be compiled to target a range of OS versions. It is best | |
100 | to not use the _MAC_* and __IPHONE_* macros for comparisons, but rather their values. | |
101 | That is because you might get compiled on an old OS that does not define a later | |
102 | OS version macro, and in the C preprocessor undefined values evaluate to zero | |
103 | in expresssions, which could cause the #if expression to evaluate in an unexpected | |
104 | way. | |
105 | ||
106 | #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED | |
107 | // code only compiled when targeting Mac OS X and not iPhone | |
108 | // note use of 1050 instead of __MAC_10_5 | |
109 | #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050 | |
110 | // code in here might run on pre-Leopard OS | |
111 | #else | |
112 | // code here can assume Leopard or later | |
113 | #endif | |
114 | #endif | |
115 | ||
116 | ||
117 | */ | |
118 | ||
fe8ab488 A |
119 | #define __MAC_10_0 1000 |
120 | #define __MAC_10_1 1010 | |
121 | #define __MAC_10_2 1020 | |
122 | #define __MAC_10_3 1030 | |
123 | #define __MAC_10_4 1040 | |
124 | #define __MAC_10_5 1050 | |
125 | #define __MAC_10_6 1060 | |
126 | #define __MAC_10_7 1070 | |
127 | #define __MAC_10_8 1080 | |
128 | #define __MAC_10_9 1090 | |
129 | #define __MAC_10_10 101000 | |
3e170ce0 A |
130 | #define __MAC_10_10_2 101002 |
131 | #define __MAC_10_10_3 101003 | |
132 | #define __MAC_10_11 101100 | |
39037602 | 133 | #define __MAC_10_12 101200 |
fe8ab488 | 134 | /* __MAC_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable */ |
6d2010ae | 135 | |
39037602 A |
136 | #define __IPHONE_2_0 20000 |
137 | #define __IPHONE_2_1 20100 | |
138 | #define __IPHONE_2_2 20200 | |
139 | #define __IPHONE_3_0 30000 | |
140 | #define __IPHONE_3_1 30100 | |
141 | #define __IPHONE_3_2 30200 | |
142 | #define __IPHONE_4_0 40000 | |
143 | #define __IPHONE_4_1 40100 | |
144 | #define __IPHONE_4_2 40200 | |
145 | #define __IPHONE_4_3 40300 | |
146 | #define __IPHONE_5_0 50000 | |
147 | #define __IPHONE_5_1 50100 | |
148 | #define __IPHONE_6_0 60000 | |
149 | #define __IPHONE_6_1 60100 | |
150 | #define __IPHONE_7_0 70000 | |
151 | #define __IPHONE_7_1 70100 | |
152 | #define __IPHONE_8_0 80000 | |
153 | #define __IPHONE_8_1 80100 | |
154 | #define __IPHONE_8_2 80200 | |
155 | #define __IPHONE_8_3 80300 | |
156 | #define __IPHONE_8_4 80400 | |
157 | #define __IPHONE_9_0 90000 | |
158 | #define __IPHONE_9_1 90100 | |
159 | #define __IPHONE_9_2 90200 | |
160 | #define __IPHONE_10_0 100000 | |
fe8ab488 | 161 | /* __IPHONE_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable */ |
6d2010ae | 162 | |
39037602 A |
163 | #define __TVOS_9_0 90000 |
164 | #define __TVOS_9_2 90200 | |
165 | #define __TVOS_10_0 100000 | |
3e170ce0 | 166 | |
39037602 A |
167 | #define __WATCHOS_1_0 10000 |
168 | #define __WATCHOS_2_0 20000 | |
169 | #define __WATCHOS_3_0 30000 | |
6d2010ae | 170 | |
3e170ce0 | 171 | #include <AvailabilityInternal.h> |
6d2010ae A |
172 | |
173 | #ifdef __IPHONE_OS_VERSION_MIN_REQUIRED | |
316670eb A |
174 | #define __OSX_AVAILABLE_STARTING(_osx, _ios) __AVAILABILITY_INTERNAL##_ios |
175 | #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) \ | |
176 | __AVAILABILITY_INTERNAL##_iosIntro##_DEP##_iosDep | |
39236c6e A |
177 | #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) \ |
178 | __AVAILABILITY_INTERNAL##_iosIntro##_DEP##_iosDep##_MSG(_msg) | |
6d2010ae A |
179 | |
180 | #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) | |
316670eb A |
181 | #define __OSX_AVAILABLE_STARTING(_osx, _ios) __AVAILABILITY_INTERNAL##_osx |
182 | #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) \ | |
183 | __AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep | |
39236c6e A |
184 | #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) \ |
185 | __AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep##_MSG(_msg) | |
6d2010ae A |
186 | |
187 | #else | |
316670eb | 188 | #define __OSX_AVAILABLE_STARTING(_osx, _ios) |
39236c6e A |
189 | #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) |
190 | #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) | |
6d2010ae A |
191 | #endif |
192 | ||
193 | ||
3e170ce0 A |
194 | #if defined(__has_feature) |
195 | #if __has_feature(attribute_availability_with_message) | |
196 | #define __OS_AVAILABILITY(_target, _availability) __attribute__((availability(_target,_availability))) | |
197 | #define __OS_AVAILABILITY_MSG(_target, _availability, _msg) __attribute__((availability(_target,_availability,message=_msg))) | |
198 | #else | |
199 | #define __OS_AVAILABILITY(_target, _availability) | |
200 | #define __OS_AVAILABILITY_MSG(_target, _availability, _msg) | |
201 | #endif | |
202 | #else | |
203 | #define __OS_AVAILABILITY(_target, _availability) | |
204 | #define __OS_AVAILABILITY_MSG(_target, _availability, _msg) | |
205 | #endif | |
206 | ||
207 | ||
208 | /* for use to document app extension usage */ | |
209 | #if defined(__has_feature) | |
210 | #if __has_feature(attribute_availability_app_extension) | |
211 | #define __OSX_EXTENSION_UNAVAILABLE(_msg) __OS_AVAILABILITY_MSG(macosx_app_extension,unavailable,_msg) | |
212 | #define __IOS_EXTENSION_UNAVAILABLE(_msg) __OS_AVAILABILITY_MSG(ios_app_extension,unavailable,_msg) | |
213 | #else | |
214 | #define __OSX_EXTENSION_UNAVAILABLE(_msg) | |
215 | #define __IOS_EXTENSION_UNAVAILABLE(_msg) | |
216 | #endif | |
217 | #else | |
218 | #define __OSX_EXTENSION_UNAVAILABLE(_msg) | |
219 | #define __IOS_EXTENSION_UNAVAILABLE(_msg) | |
220 | #endif | |
221 | ||
222 | #define __OS_EXTENSION_UNAVAILABLE(_msg) __OSX_EXTENSION_UNAVAILABLE(_msg) __IOS_EXTENSION_UNAVAILABLE(_msg) | |
223 | ||
224 | ||
225 | ||
226 | /* for use marking APIs available info for Mac OSX */ | |
227 | #if defined(__has_feature) | |
228 | #if __has_attribute(availability) | |
229 | #define __OSX_UNAVAILABLE __OS_AVAILABILITY(macosx,unavailable) | |
230 | #define __OSX_AVAILABLE(_vers) __OS_AVAILABILITY(macosx,introduced=_vers) | |
231 | #define __OSX_DEPRECATED(_start, _dep, _msg) __OSX_AVAILABLE(_start) __OS_AVAILABILITY_MSG(macosx,deprecated=_dep,_msg) | |
232 | #endif | |
233 | #endif | |
234 | ||
235 | #ifndef __OSX_UNAVAILABLE | |
236 | #define __OSX_UNAVAILABLE | |
237 | #endif | |
238 | ||
239 | #ifndef __OSX_AVAILABLE | |
240 | #define __OSX_AVAILABLE(_vers) | |
241 | #endif | |
242 | ||
243 | #ifndef __OSX_DEPRECATED | |
244 | #define __OSX_DEPRECATED(_start, _dep, _msg) | |
245 | #endif | |
246 | ||
247 | ||
248 | /* for use marking APIs available info for iOS */ | |
249 | #if defined(__has_feature) | |
250 | #if __has_attribute(availability) | |
251 | #define __IOS_UNAVAILABLE __OS_AVAILABILITY(ios,unavailable) | |
252 | #define __IOS_PROHIBITED __OS_AVAILABILITY(ios,unavailable) | |
253 | #define __IOS_AVAILABLE(_vers) __OS_AVAILABILITY(ios,introduced=_vers) | |
254 | #define __IOS_DEPRECATED(_start, _dep, _msg) __IOS_AVAILABLE(_start) __OS_AVAILABILITY_MSG(ios,deprecated=_dep,_msg) | |
255 | #endif | |
256 | #endif | |
257 | ||
258 | #ifndef __IOS_UNAVAILABLE | |
259 | #define __IOS_UNAVAILABLE | |
260 | #endif | |
261 | ||
262 | #ifndef __IOS_PROHIBITED | |
263 | #define __IOS_PROHIBITED | |
264 | #endif | |
265 | ||
266 | #ifndef __IOS_AVAILABLE | |
267 | #define __IOS_AVAILABLE(_vers) | |
268 | #endif | |
269 | ||
270 | #ifndef __IOS_DEPRECATED | |
271 | #define __IOS_DEPRECATED(_start, _dep, _msg) | |
272 | #endif | |
273 | ||
274 | ||
275 | /* for use marking APIs available info for tvOS */ | |
276 | #if defined(__has_feature) | |
277 | #if __has_feature(attribute_availability_tvos) | |
278 | #define __TVOS_UNAVAILABLE __OS_AVAILABILITY(tvos,unavailable) | |
279 | #define __TVOS_PROHIBITED __OS_AVAILABILITY(tvos,unavailable) | |
280 | #define __TVOS_AVAILABLE(_vers) __OS_AVAILABILITY(tvos,introduced=_vers) | |
281 | #define __TVOS_DEPRECATED(_start, _dep, _msg) __TVOS_AVAILABLE(_start) __OS_AVAILABILITY_MSG(tvos,deprecated=_dep,_msg) | |
282 | #endif | |
283 | #endif | |
284 | ||
285 | #ifndef __TVOS_UNAVAILABLE | |
286 | #define __TVOS_UNAVAILABLE | |
287 | #endif | |
288 | ||
289 | #ifndef __TVOS_PROHIBITED | |
290 | #define __TVOS_PROHIBITED | |
291 | #endif | |
292 | ||
293 | #ifndef __TVOS_AVAILABLE | |
294 | #define __TVOS_AVAILABLE(_vers) | |
295 | #endif | |
296 | ||
297 | #ifndef __TVOS_DEPRECATED | |
298 | #define __TVOS_DEPRECATED(_start, _dep, _msg) | |
299 | #endif | |
300 | ||
301 | ||
302 | /* for use marking APIs available info for Watch OS */ | |
303 | #if defined(__has_feature) | |
304 | #if __has_feature(attribute_availability_watchos) | |
305 | #define __WATCHOS_UNAVAILABLE __OS_AVAILABILITY(watchos,unavailable) | |
306 | #define __WATCHOS_PROHIBITED __OS_AVAILABILITY(watchos,unavailable) | |
307 | #define __WATCHOS_AVAILABLE(_vers) __OS_AVAILABILITY(watchos,introduced=_vers) | |
308 | #define __WATCHOS_DEPRECATED(_start, _dep, _msg) __WATCHOS_AVAILABLE(_start) __OS_AVAILABILITY_MSG(watchos,deprecated=_dep,_msg) | |
309 | #endif | |
310 | #endif | |
311 | ||
312 | #ifndef __WATCHOS_UNAVAILABLE | |
313 | #define __WATCHOS_UNAVAILABLE | |
314 | #endif | |
315 | ||
316 | #ifndef __WATCHOS_PROHIBITED | |
317 | #define __WATCHOS_PROHIBITED | |
318 | #endif | |
319 | ||
320 | #ifndef __WATCHOS_AVAILABLE | |
321 | #define __WATCHOS_AVAILABLE(_vers) | |
322 | #endif | |
323 | ||
324 | #ifndef __WATCHOS_DEPRECATED | |
325 | #define __WATCHOS_DEPRECATED(_start, _dep, _msg) | |
326 | #endif | |
327 | ||
39037602 A |
328 | #if __has_include(<AvailabilityProhibitedInternal.h>) |
329 | #include <AvailabilityProhibitedInternal.h> | |
330 | #endif | |
3e170ce0 | 331 | |
6d2010ae | 332 | #endif /* __AVAILABILITY__ */ |