Objective-C对象方法
//第一个Objective-C对象方法
//编写类的声明
#import<Foundation?Foundation.h>
@interface Iphone: NSObject
{
@public
flaot _model; //型号
int _cpu; //cpu
double _size; //尺寸
int _color; //颜色
}
//行为
-(void)about;
@end
//编写类的实现
@implementation Iphone
//行为的实现
-(void)about
{
NSLog(@"打印本机信息");
}
@end
int main(int argc, const char * argv[]){
@autoreleasepool{
NSLog(@"Hello,World");
//通过类创建对象
Iphone *p=[Iphone new];
p->_model=4S;
p->_cpu=1;
p->_size=3.5;
p->_color=0;
//获取对象的属性
NSLog(@"model=%f,cpu=%d,size=%f,color=%d",p->_model,p->_cpu,p->_size,p->_color);
[p about];
}
return 0;
}

浙公网安备 33010602011771号