clang -rewrite-objc 的作用是把oc代碼轉(zhuǎn)寫成c/c++代碼护奈,常用它來查看OC的底層實(shí)現(xiàn)贝椿。
1.基本使用
//使用命令行進(jìn)入main.m的目錄,執(zhí)行下面的命令
clang -rewrite-objc main.m
//會(huì)產(chǎn)生一個(gè)main.cpp文件
2.查看機(jī)器上裝有的的sdk
xcodebuild -showsdks
iOS SDKs:
iOS 11.1 -sdk iphoneos11.1
iOS Simulator SDKs:
Simulator - iOS 11.1 -sdk iphonesimulator11.1
macOS SDKs:
macOS 10.13 -sdk macosx10.13
tvOS SDKs:
tvOS 11.1 -sdk appletvos11.1
tvOS Simulator SDKs:
Simulator - tvOS 11.1 -sdk appletvsimulator11.1
watchOS SDKs:
watchOS 4.1 -sdk watchos4.1
watchOS Simulator SDKs:
Simulator - watchOS 4.1 -sdk watchsimulator4.1
3.具體情況
//指定真機(jī)
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
//指定framework
xcrun -sdk iphonesimulator11.1 clang -rewrite-objc -F /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks main.m
//可以同時(shí)指定多個(gè)源文件态兴、多個(gè)framework