clang -rewrite-objc 的作用是把oc代码转写成c/c++代码,常用它来查看OC的底层实现。
1.基本使用
//使用命令行进入main.m的目录,执行下面的命令clang -rewrite-objc main.m//会产生一个main.cpp文件复制代码
2.查看机器上装有的的sdk
xcodebuild -showsdks iOS SDKs: iOS 11.1 -sdk iphoneos11.1iOS Simulator SDKs: Simulator - iOS 11.1 -sdk iphonesimulator11.1macOS SDKs: macOS 10.13 -sdk macosx10.13tvOS SDKs: tvOS 11.1 -sdk appletvos11.1tvOS Simulator SDKs: Simulator - tvOS 11.1 -sdk appletvsimulator11.1watchOS SDKs: watchOS 4.1 -sdk watchos4.1watchOS Simulator SDKs: Simulator - watchOS 4.1 -sdk watchsimulator4.1复制代码
3.具体情况
//指定真机xcrun -sdk iphoneos clang -rewrite-objc main.m //指定模拟器xcrun -sdk iphonesimulator clang -rewrite-objc main.m //指定SDK版本xcrun -sdk iphonesimulator10.3 clang -rewrite-objc main.m //指定frameworkxcrun -sdk iphonesimulator11.1 clang -rewrite-objc -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks main.m //可以同时指定多个源文件、多个framework复制代码