0
我有以下特性:的NSDictionary:比較後MutableCopy
@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是否將其副本更改爲其中沒有更改任何內容的位置,將它與源對比並且它不相同?我無法弄清楚我做錯了什麼!
if([dataClass.firstLocationAddressObject isEqualToDictionary:dataClass.firstLocationAddressObject])爲什麼你這樣比較這種情況? –
你是什麼意思?我需要比較字典以查看是否有任何鍵值已更改。 – user1107173
不,我的意思是,你是比較你的兩個數據類的條件,儘管我的一類 –