gpt4 book ai didi

ios - Xcode中如何知道Objective-C语言版本

转载 作者:搜寻专家 更新时间:2023-10-30 20:08:36 25 4
gpt4 key购买 nike

有什么方法可以检查我在我的应用程序中使用的 Objective-C 版本

最佳答案

Objective-C 语言支持级别由用于编译代码的 Clang 版本定义,它本身非常接近 Xcode 的版本。

#if __clang_major__ >= 11
NSLog(@"My Objective-C language support is what Apple Clang/Xcode 11.x can support.");
// This language version supports the additional features/fixes written under "Apple Clang Compiler"
// https://developer.apple.com/documentation/xcode_release_notes/xcode_11_release_notes
// Notably this version adds Objective-C support to:
// - `[[clang::no_destroy]]` and `[[clang::always_destroy]]`

#elif __clang_major__ >= 10
NSLog(@"My Objective-C language support is what Apple Clang/Xcode 10.x can support.");
// This language version supports the additional features/fixes written under "Apple Clang Compiler"
// https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
// Notably this version adds macro support to:
// - detect most builtin pseudo-functions with `__has_builtin`

#elif __clang_major__ >= 9
NSLog(@"My Objective-C language support is what Apple Clang/Xcode 9.x can support.");
// This language version supports the additional features/fixes written under "Apple LLVM Compiler and Low-Level Tools"
// https://developer.apple.com/library/archive/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW878
// Notably this version adds Objective-C support for:
// - the `@available` language feature

#elif __clang_major__ >= 8
NSLog(@"My Objective-C language support is what Apple Clang/Xcode 8.x can support.");
// This language version supports the additional features/fixes written under "Objective-C and C++"
// https://developer.apple.com/library/archive/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW78
// Notably this version adds Objective-C support for:
// - the `@property (class)` language feature

#elif __clang_major__ >= 7
NSLog(@"My Objective-C language support is what Apple Clang/Xcode 7.x can support.");
// This language version supports the additional features/fixes written under "Objective-C"
// https://developer.apple.com/library/archive/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW326
// Notably this version adds Objective-C support for:
// - `CF_RETURNS_NOT_RETAINED` and `CF_RETURNS_RETAINED`
// - `__kindof`
// - `_Nullable`, `_Nonnull`, and `_Null_unspecified`
// - Lightweight generics like `NSArray<UIImage *> *` and `NSDictionary<NSString *, NSURL *>`

#elif __clang_major__ >= 6
NSLog(@"My Objective-C language support is what Apple Clang/Xcode 6.x can support.");
// This language version supports the additional features/fixes written at:
// https://developer.apple.com/library/archive/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW453

#else
NSLog(@"My Objective-C language support is so old that I won't even be allowed to publish this on any App Store nowadays.");

#endif

如果您需要更精确的版本,您也可以使用 __clang_minor__

只要有可能,建议使用 __has_builtin检查 Objective-C 语言功能的可用性,而不是 __clang_major____clang_minor__

一些值得注意的其他较旧的历史语言功能,您甚至不应该再费心测试可用性了:

  • NS_ENUMNS_OPTIONS 已添加到 Xcode 4.5
  • NSDictionaryNSArray 下标已在 Xcode 4.4/4.5 中添加
  • @YES@NO 文字已添加到 Xcode 4.4/4.5
  • NSNumberNSDictionaryNSArray 文字已添加到 Xcode 4.4
  • @autoreleasepool block 已添加到 Xcode 4.2
  • Objective-C 2.0”是非常古老的东西(Xcode 2.x)

最后,“Modern Objective-C”仅指任何当前可用的 Xcode 对 Objective-C 的支持。

相关:

关于ios - Xcode中如何知道Objective-C语言版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37608546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com