美文网首页
iOS------[__NSDictionaryI remove

iOS------[__NSDictionaryI remove

作者: 彬至睢阳 | 来源:发表于2021-09-15 15:09 被阅读0次

现象1

NSMutableDictionary*dict = [[NSMutableDictionary alloc]initWithDictionary:@{@"type":@"",@"START_NO":@"",@"END_NO":@"",@"SUM":@"",@"DOC_TYPE":@"",@"CCY":@"",@"FLAG":@""}];

NSArraylista =[[NSArray alloc]initWithObjects:dict, nil];
for (NSMutableDictionary
dict in lista) {

    [dict removeObjectForKey:@"type"];
}
NSLog(@"%@",lista);

输出为:
(
{
CCY = "";
"DOC_TYPE" = "";
"END_NO" = "";
FLAG = "";
"START_NO" = "";
SUM = "";
}
)

现象2:
NSMutableDictionarydict = [[NSMutableDictionary alloc]initWithDictionary:@{@"type":@"",@"START_NO":@"",@"END_NO":@"",@"SUM":@"",@"DOC_TYPE":@"",@"CCY":@"",@"FLAG":@""}];
NSMutableArray
lista =[[NSMutableArray alloc]init];
[lista addObject:dict];

for (NSMutableDictionary*dict in lista) {
    
    [dict removeObjectForKey:@"type"];
}
NSLog(@"%@",lista);

(
{
CCY = "";
"DOC_TYPE" = "";
"END_NO" = "";
FLAG = "";
"START_NO" = "";
SUM = "";
}
)

总结:
不管数组是可变或者是不可变的,只要数组内的字典为可变的,那就可以删除字典内的元素,以for in 顺便也将数组中字典的删除。

现象3:
NSDictionarydict = @{@"type":@"",@"START_NO":@"",@"END_NO":@"",@"SUM":@"",@"DOC_TYPE":@"",@"CCY":@"",@"FLAG":@""};
NSMutableArray
lista =[[NSMutableArray alloc]init];
[lista addObject:dict];

for (NSMutableDictionary*dict in lista) {
    
    [dict removeObjectForKey:@"type"];
}
NSLog(@"%@",lista);

结果:*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI removeObjectForKey:]: unrecognized selector sent to instance 0x600003ad0d20'

总结:不管数组是可变还是不可变的,如果数组内的字典为不可变的,NSMutableDictionary*dict in lista的字典还是不可变的,切记。

相关文章

网友评论

      本文标题:iOS------[__NSDictionaryI remove

      本文链接:https://www.haomeiwen.com/subject/ggnkgltx.html