iphone 个人使用总结
1:创建一个car对象
头文件:
@interface car : NSObject {
}
@end
实现文件:
@implementation car
-(id) init
{
if (self = [super init]) {
NSLog(@"this is my name!and what's your name!");
}
return(self);
}//init
@end
实践得出的结果:
1若使用new创建的对象,则会自动调用方法init,代码如下:
car *newCar = [car new];
2如果使用alloc创建对象时,则需要手动调用方法:init。
浙公网安备 33010602011771号