- iOS从零基础到精通就业 Objective-C
- CSDN观看地址:http://edu.csdn.net/course/detail/3347
- 属性
-
#import <Foundation/Foundation.h> #import "Car.h" #import "Phone.h" int main(int argc, const char * argv[]) { Car *c1 = [[Car alloc] init]; Car *c2 = [[Car alloc] initWithBrand:@"QQ" price:40000.0]; //给c1设置品牌和价格 [c1 setBrand:@"兰博基尼"]; [c1 setPrice:3000000.0]; NSLog(@"%@ %.2f",[c1 brand],[c1 price]); //创建手机 Phone *p1 = [[Phone alloc] init]; //设置属性 /* [p1 setBrand:@"诺基亚"]; [p1 setColor:@"白色"]; [p1 setPrice:2000.0]; [p1 setAddress:@"中国"]; */ //用点语法代替 p1.brand = @"诺基亚"; p1.color = @"白色"; NSLog(@"手机是%@品牌的",p1.brand); //用KVC赋值(以间接的方式对属性进行赋值) [p1 setValue:@"摩托罗拉" forKey:@"brand"]; [p1 setValue:@"墨绿色" forKey:@"color"]; NSLog(@"手机是%@品牌的",p1.brand); return 0; }