通过clang看OC底层C++文件

想了解oc底层的c++文件是怎样的,然后执行clang -rewrite-objc ViewController.m时报错

In file included from ViewController.m:9:
./ViewController.h:9:9: fatal error: 'UIKit/UIKit.h' file not found
#import 
        ^~~~~~~~~~~~~~~
1 error generated.

解决办法:

clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk xxxxx.m

可通过alias简化如下:

1、进入终端输入
vim ~/.bash_profile

2、在vim界面输入i进入编辑状态然后输入:
alias writeoctoc='clang -x objective-c -rewrite-objc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk'

3、点esc退出编辑状态,再键入:wq(退出vim并保存),执行source ~/.bash_profile
4、进入你想要编译的文件目录
8447B1D5-7FB4-451A-8FF4-A271A3704CA4.png
5、执行writeoctoc xxx.m即可成功
9B49252D-75DA-4F0C-8C6C-E9ED56A05572.png
94221A85-F0F0-4B03-8516-24DD4A5823A8.png

你可能感兴趣的:(通过clang看OC底层C++文件)