[Objective-C] @property是不能被“预处理”的,而是直接编译成汇编指令
2015-07-07 07:27
344 查看
参考:http://stackoverflow.com/questions/31241643/how-can-i-get-direcitve-preprocessed-objective-c-code
对于下面的Objc代码,我们想看到@property被“预处理”之后长什么样子
如果一定要深究最终编译器做了些什么,它把 @property、@synthesize 是怎么处理的,可以在 XCode 中点击菜单中的 Product -> Perform Action -> Assemble XXX 来查看最终的汇编代码。
对于下面的Objc代码,我们想看到@property被“预处理”之后长什么样子
// ========= Person.h ========= @interface Person: NSObject { } -(void) Print; @property int age; @end // ========= Person.m ========= @implementation Person -(void) Print { NSLog(@"Print_Age:%d", _age); } @end我们期望看到它是长这样的:
// ========= Person.h ========= @interface Person: NSObject { int _age; } -(void) Print; -(int) age; -(void) setAge:(int) age; @end // ========= Person.m ========= @implementation Person -(void) Print { NSLog(@"Print_Age:%d", _age); } -(int) age { return _age; } -(void) setAge:(int) age { _age = age; } @end事实上,最终的代码确实可以理解成是上面那样的。但是要注意的是,@property、@synthesize 这样的东西不像 #define xxx yyy 是可以被编译器预处理的,@property、@synthesize 会被编译器直接编译成汇编代码,不存在“预处理中间代码”阶段,因此我们不可能看到上面那样的“中间代码”。就好比 for/while/switch/case 这样的最基本的关键字,它们最终是怎么工作的,编译器不会通过中间代码的形式呈现给用户,而是直接编译成汇编指令。
如果一定要深究最终编译器做了些什么,它把 @property、@synthesize 是怎么处理的,可以在 XCode 中点击菜单中的 Product -> Perform Action -> Assemble XXX 来查看最终的汇编代码。
相关文章推荐
- Object-Oriented Terms 面向对象术语
- Objective-C 中的 Meta-class 是什么
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第十一章 分类和协议
- 运行时runbime
- iOS_Objective-C_控件中的字体加粗
- ./show_file: error while loading shared libraries: libts-0.0.so.0: cannot open shared object file: N
- [Objective-C] 012_数据持久化_XML属性列表,NSUserDefaults
- IOS 关于objc_setAssociatedObject,objc_getAssociatedObject
- object-c的异常处理机制
- Objective-C中获取类名
- JSONObject基本内容(二)
- JSONObject基本内容(一)
- [Objective-C] property setter/getter via @property
- 【Effective Objective-C 2.0读书笔记】第三章:接口和API设计
- Object与equals与HashCode
- byte to object and object to byte
- Objective-C语法之NSString与int和float的相互转换
- Objective-C Runtime中的并发内存分配
- html之object标签的classid收集
- IOS中的关联对象实现objc_setAssociatedObject