NSMutableDictionary

NSMutableDictionary

网上:
NSMutableDictionary *dict = [NSMutableDictionary dictionary];

[dict setObject:@"John" forKey:@"Firstname"];
[dict setObject:@"Doe" forKey:@"Lastname"];
[dict setObject:@"[email protected]" forKey:@"Email"];

NSLog(@"%@===aaa", dict);

NSArray *keys = [dict allKeys];

// values in foreach loop
for (NSString *key in keys) {
NSLog(@"%@ is %@",key, [dict objectForKey:key]);
}

[dict removeObjectForKey:@"Email"];

自己:

NSMutableDictionary *d=[[NSMutableDictionary alloc]init];
[d setObject:@"zhang" forKey:@"z"];
[d setObject:@"ming" forKey:@"m"];
[d setObject:@"wei" forKey:@"w"];
NSLog(@"%@",[d objectForKey:@"w"]);
NSArray *keys1=[d allKeys];
for (NSString *key1 in keys1) {
NSLog(@"%@ is %@",key1,[d objectForKey:key1]);
}
[d removeObjectForKey:@"z"];
for (NSString *key1 in keys1) {
NSLog(@"%@ is %@",key1,[d objectForKey:key1]);
}
控制台:
2012-08-22 20:14:13.996 Student[3066:707] {
Email = "[email protected]";
Firstname = John;
Lastname = Doe;
}===aaa
2012-08-22 20:14:14.090 Student[3066:707] Email is [email protected]
2012-08-22 20:14:14.125 Student[3066:707] Firstname is John
2012-08-22 20:14:14.126 Student[3066:707] Lastname is Doe
2012-08-22 20:14:14.127 Student[3066:707] wei
2012-08-22 20:14:14.128 Student[3066:707] z is zhang
2012-08-22 20:14:14.129 Student[3066:707] m is ming
2012-08-22 20:14:14.129 Student[3066:707] w is wei
2012-08-22 20:14:14.130 Student[3066:707] z is (null)
2012-08-22 20:14:14.130 Student[3066:707] m is ming
2012-08-22 20:14:14.131 Student[3066:707] w is wei

你可能感兴趣的:(Objective-C)