iOS clang -rewrite-objc

2018-09-12  本文已影响21人  烟雨痕

一、终端使用clang命令将OC代码转成C代码

终端cd 到包含文件工程文件的目录

输入指令: clang -rewrite-objc main.m
main.m:9:9: fatal error: 'UIKit/UIKit.h' file not found
#import <UIKit/UIKit.h>
        ^~~~~~~~~~~~~~~
1 error generated.

修改输入指令:xcrun -sdk iphonesimulator11.2 clang -rewrite-objc -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS11.2.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks SecondViewController.m

iphonesimulator11.2 中 11.2 为当前xcode SDK版本号(指令xcodebuild -showsdks即可查看)

下面错误解决 参考: https://www.jianshu.com/p/3f6b3d0cb598

出现错误:
cannot create __weak reference because the current deployment target does
      not support weak references
    __attribute__((objc_ownership(weak))) typeof(self) weakSelf = self;

修改输入指令:clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk -fobjc-arc -stdlib=libc++ -mmacosx-version-min=10.13 -fobjc-runtime=macosx-10.13 -Wno-deprecated-declarations 需要转换的文件名.m

指令中:macosx-version-min=10.13 -fobjc-runtime=macosx-10.13修改为你的mac系统版本号
上一篇下一篇

猜你喜欢

热点阅读