首页 > 代码库 > KVC的应用

KVC的应用

//    Student *stu=[[Student alloc]init];

//    [stu setValue:@12 forKey:@"age"];

//    [stu setValue:@14 forKey:@"_age"];

//    [stu setValue:@"zhangsan" forKey:@"name"];

//    [stu setValue:@"lisi" forKey:@"_name"];

//    [stu call];

//    

//    Book *book=[[Book alloc]init];

//    [stu setValue:book forKey:@"book"];

//    

//    [stu setValue:@"nihao" forKeyPath:@"book.title"];

//    [stu call];

    

    

//    NSString *path=[[NSBundle mainBundle]pathForResource:@"json" ofType:@"txt"];

//    NSString *jsonStr=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

//    NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:[jsonStr dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];

//    

//    News *news=[[News alloc]init];

//    [news setValuesForKeysWithDictionary:dict];

//    NSLog(@"%@",news.Name);

//    NSLog(@"----");

    

//    Student *s1=[[Student alloc]init];

//    s1.age=12;

//    Student *s2=[[Student alloc]init];

//    s2.age=13;

//    Student *s3=[[Student alloc]init];

//    s3.age=14;

//    Student *s4=[[Student alloc]init];

//    s4.age=15;

//    NSArray *arr=@[s1,s2,s3,s4];

//    NSLog(@"%@",[arr valueForKey:@"@count"]);

//    NSLog(@"%@",[arr valueForKeyPath:@"@min.age"]);

//    NSLog(@"%@",[arr valueForKeyPath:@"@sum.age"]);

KVC的应用