OC匿名对象
2015-11-19 23:00
471 查看
#import <Foundation/Foundation.h> @interface Car : NSObject { @public int speed; } - (void)run; @end @implementation Car - (void)run{ NSLog(@"速度为%d的车子跑起来了",speed); } @end int main() { //不要写类似匿名对象这样的代码//造成内存泄露 [Car new]->speed = 300; //匿名方法//上下两个[Car new]都不一样 [[Car new] run]; //每次[Car new]调用都会创建一个新对象 // Car *c; // c = [Car new]; // c->speed = 250; // // [c run]; return 0; }
相关文章推荐
- Objective-C的内省(Introspection)用法小结
- Objective-C中常用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect实例分析
- Objective-C中NSNumber与NSDictionary的用法简介
- Objective-C中NSLog输出格式大全
- 全面解析Objective-C中的block代码块的使用
- Swift调用Objective-C编写的API实例
- Swift、Objective-C、Cocoa混合编程设置指南
- Objective-c代码如何移植为Swift代码 Objective-c代码转移到Swift过程介绍
- Swift调用Objective-C代码
- 以实例讲解Objective-C中的KVO与KVC机制
- objective-c中生成随机数的方法
- 在Swift中使用Objective-C编写类、继承Objective-C类
- Swift能代替Objective-C吗?
- Objective-C 消息传递机制详解
- 在一个项目中同时使用Swift和Objective-C代码混合编程的方法
- vm安装mac os x 10.7 lion
- objective-c(一)
- objective-c(二)
- objective-c(三)