您的位置:首页 > 其它

63,匿名对象

2015-12-06 12:05 330 查看
#import <Foundation/Foundation.h>

@interface Iphone :
NSObject

-(void)getBrand;

@end

@implementation Iphone

-(void)getBrand{

NSLog(@"苹果手机");

}

@end

int main(int argc,
const char * argv[]) {

@autoreleasepool {

//1,有名称的对象

Iphone *p = [Iphone
new];

[p getBrand];

//2,匿名对象

//适用场景:只使用一次就使用匿名对象——对象作为一次性参数传入或使用

[[Iphone new]
getBrand];

}

return 0;

}

//2015-12-06 12:03:29.209 6,匿名对象[1041:82129]
苹果手机

//2015-12-06 12:03:29.210 6,匿名对象[1041:82129]
苹果手机

//Program ended with exit code: 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: