我有以下属性:
@property (retain, nonatomic) NSMutableDictionary * firstStartTimeObject;
@property (retain, nonatomic) NSMutableDictionary * firstLocationNameObject;
@property (retain, nonatomic) NSMutableDictionary * firstLocationAddressObject;
@property (retain, nonatomic) NSMutableDictionary * secondStartTimeObject;
@property (retain, nonatomic) NSMutableDictionary * secondLocationNameObject;
@property (retain, nonatomic) NSMutableDictionary * secondLocationAddressObject;
//这就是我复制字典的方式:
-(DataClass *)copyObjects
{
DataClass *newClass = [[DataClass alloc]init];
newClass.firstStartTimeObject = [firstStartTimeObject mutableCopy];
newClass.firstLocationAddressObject = [firstLocationAddressObject mutableCopy];
newClass.firstLocationNameObject = [firstLocationNameObject mutableCopy];
newClass.secondStartTimeObject = [secondStartTimeObject mutableCopy];
newClass.secondLocationNameObject = [secondLocationNameObject mutableCopy];
newClass.secondLocationAddressObject = [secondLocationAddressObject mutableCopy];
return newClass;
}
//在另一个类中我比较它们
if([myClass.firstStartTimeObject isEqualToDictionary:dataClass.firstStartTimeObject])
{
[dataClass.firstStartTimeObject setValue:kCellBackGroundColor forKey:kBackGround];
}
if([myClass.firstLocationNameObject isEqualToDictionary:dataClass.firstLocationNameObject])
{
[dataClass.firstLocationNameObject setValue:kCellBackGroundColor forKey:kBackGround];
}
if([dataClass.firstLocationAddressObject isEqualToDictionary:dataClass.firstLocationAddressObject])
{
[dataClass.firstLocationAddressObject setValue:kCellBackGroundColor forKey:kBackGround];
}
if([myClass.secondStartTimeObject isEqualToDictionary:dataClass.secondStartTimeObject])
{
[dataClass.secondStartTimeObject setValue:kCellBackGroundColor forKey:kBackGround];
}
if([myClass.secondLocationNameObject isEqualToDictionary:dataClass.secondLocationNameObject])
{
[dataClass.secondLocationNameObject setValue:kCellBackGroundColor forKey:kBackGround];
}
if([myClass.secondLocationAddressObject isEqualToDictionary:dataClass.secondLocationAddressObject])
{
[dataClass.secondLocationAddressObject setValue:kCellBackGroundColor forKey:kBackGround];
}
我有断点设置。比较字典中的键/值是相同的,但编译器似乎以不同的方式看待它们,因为条件永远不会为真,使其位于大括号内并命中断点。
我通过 NSLog 验证了键/值,它们是相同的。我什至尝试了协议- (id)mutableCopyWithZone:(NSZone *)zone
并得到了相同的行为。
NSMutableDicitonary 的 mutableCopy 是否将其副本更改为不更改其任何内容的位置,您将其与源进行比较并且它不一样?我无法弄清楚我做错了什么!