蓝鸥iOS从零基础到精通就业-OC语言入门 属性1

  • 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;
    }
    
    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值