字典 可变字典 大杂烩
来源:互联网 发布:字符串数组 strstr 编辑:程序博客网 时间:2024/05/01 11:47
//不可变字典 Student *s7=[[Student alloc]initWithName:@"jack"]; NSDictionary *dic=[[NSDictionary alloc]initWithObjectsAndKeys:s7,@"jack",@"26",@"age", nil]; NSString* str15=[dic objectForKey:@"age"];//objectForKey 获取对象 NSLog(@"%@",str15); Student *s8=(Student *)[dic objectForKey:@"jack"]; [s8 showInfo]; NSArray *keys= [dic allKeys]; //获取 数组里面的 所有的KEY NSLog(@"keys =%@",keys); // NSArray *values=[dic allValues];// NSLog(@"%@“,va)// allvalues; //可变字典 Student *s9=[[Student alloc]initWithName:@"rose"]; NSMutableDictionary *mutableDic=[[NSMutableDictionary alloc]initWithCapacity:0]; [mutableDic setValue:s9 forKey:@"rose"]; [mutableDic setValue:@"26" forKey:@"lucy"]; [mutableDic removeObjectForKey:@"lucy"];//移除 Student *s10=(Student *)[mutableDic objectForKey:@"rose"]; [s10 showInfo];