SafeObject icon indicating copy to clipboard operation
SafeObject copied to clipboard

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

Open WHaveFun opened this issue 5 years ago • 0 comments

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<NSCopying> *)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; }

WHaveFun avatar Dec 11 '18 09:12 WHaveFun