// 匿名对象
main.h
#import <Foundation/Foundation.h>
#import "Dog.h"
int main(int argc, const char * argv[])
{
Dog *dog = [Dog new];
dog->speed = 30;
[dog run];
[dog new];
[dog new]->speed = 30;
[[dog new] run];
// 每出现一次[dog new]会创建一个对象
return 0;
}
Dog.h
#import <Foundation/Foundation.h>
@interface Dog : NSObject
{
@public
int speed;
}
- (void)run;
@end
Dog.m
#import <Dog.h>
@implementation Dog
- (void)run
{
NSLog(@"狗跑起来了,速度是%d",speed);
}
@end
网友评论