Skip to content

@{} 设置字典,导致元素随机减少 #1

@WHaveFun

Description

@WHaveFun

UILabel *label = [UILabel new];
NSDictionary *dataDic = @{
@"123":@"123",
@"1232":@"1233",
@"1233":@"1243",
@"123e":@"123d",
@"12345": label.text,
@"1asd":@"123",
@"dfg":@"1233",
};
MYLog(@"-----%@",dataDic)
打印结果如下:
-----{
123 = 123;
1232 = 1233;
1233 = 1243;
123e = 123d;
}

NSDictionary+Safe

-(instancetype)initWithObjects_st:(id *)objects forKeys:(id *)keys count:(NSUInteger)count {
NSUInteger rightCount = 0;
for (NSUInteger i = 0; i < count; i++) {
if (!(keys[i] && objects[i])) {
///此处会导致字典元素减少较多
break;
}else{
rightCount++;
}
}
self = [self initWithObjects_st:objects forKeys:keys count:rightCount];
return self;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions