这次遇到的问题是xcode15+ios17.sdk编译没问题,但换成低版本clang(clang<=13)会报如下错误:
In file included from /Users/apple/Documents/xcodetest/aa/aa/main.m:8:
In file included from /Applications/Xcode15.2.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:13:
In file included from /Applications/Xcode15.2.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSBundle.h:6:
/Applications/Xcode15.2.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:378:81: error: function does not return string type
- (nullable instancetype)initWithUTF8String:(const char *)nullTerminatedCString NS_FORMAT_ARGUMENT(1);
简单搜了下很多人都遇到过此问题,经过跟踪发现ios17.sdk中很多地方用到了NS_FORMAT_ARGUMENT,首次触发报错在NSString.h中,而低版本xcode对应的低版本sdk中没有用该宏
,而NS_FORMAT_ARGUMENT用到了format_arg,经过测试可以发现clang<=13是不支持format_arg的。所以以上报错与clang/iphone_sdk都有关。那么有没有办法解决呢?这里提供一个方案:
- 在include 第一个oc头文件之前
#define format_arg(n) - Build Settings -> Enable Modules -> No
编译成功