字典
NSDictionary *dictionary = @{@"key1" : @"value1", @"key2" : @"value2"};NSDictionary *dictionary2 = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
[dictionary setObject:@"newValue" forKey:@"key1"]; // 错误,不可变字典不能修改
NSString *value = dictionary[@"key1"];BOOL containsKey = [dictionary containsKey:@"key3"];
NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] init];
[mutableDictionary setObject:@"value1" forKey:@"key1"];
[mutableDictionary removeObjectForKey:@"key1"];
[mutableDictionary setObject:@"newValue" forKey:@"key1"];
Last updated