Objective-C语言从可变字典中删除条目
示例
-removeObjectForKey:
从字典中删除给定的键及其关联的值。
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"key1":@"Easy",@"key2": @"Tutorials"}]; [dict removeObjectForKey:@"key1"]; NSLog(@"%@",dict);
输出值
{ key2 = Tutorials; }
-removeAllObjects
清空字典的条目。
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"key1":@"Eezy",@"key2": @"Tutorials"}]; [dict removeAllObjects]; NSLog(@"%@",dict);
输出值
{ }
-removeObjectsForKeys:
从字典中删除由给定数组中的元素指定的条目。
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"key1":@"Easy",@"key2": @"Tutorials"}]; [dict removeObjectsForKeys:@[@"key1"]]; NSLog(@"%@",dict);
输出值
{ key2 = Tutorials; }