從可變字典中刪除條目

- removeObjectForKey:

從字典中刪除給定的鍵及其關聯值。

NSMutableDictionary *dict =  [NSMutableDictionary dictionaryWithDictionary:@{@"key1":@"Easy",@"key2": @"Tutorials"}];
[dict removeObjectForKey:@"key1"];
NSLog(@"%@",dict);

OUTPUT

{
    key2 = Tutorials;
} 

- removeAllObjects

清空其條目的字典。

NSMutableDictionary *dict =  [NSMutableDictionary dictionaryWithDictionary:@{@"key1":@"Eezy",@"key2": @"Tutorials"}];
[dict removeAllObjects];
NSLog(@"%@",dict);

OUTPUT

{
}

- removeObjectsForKeys:

從給定陣列中的元素指定的字典條目中刪除。

NSMutableDictionary *dict =  [NSMutableDictionary dictionaryWithDictionary:@{@"key1":@"Easy",@"key2": @"Tutorials"}];
[dict removeObjectsForKeys:@[@"key1"]];
NSLog(@"%@",dict);

OUTPUT

{
    key2 = Tutorials;
}