Pergunta

I have the following properties:

@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;

//This is how I make copies of the Dictionaries:

-(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;
}

//In another Class I compare them

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];
}

I have Break points setup. Keys/Values in comparing dictionaries is identical, but it seems like the compiler looks at them differently as the condition is never true for it to make it inside the braces and hit the breakpoint.

I verified the keys/values via NSLog and they are identical. I even tried protocol with - (id)mutableCopyWithZone:(NSZone *)zone and got the same behavior.

Does mutableCopy of an NSMutableDicitonary change its copy to where without changing any of its contents, you compare it to the source and it's not the same? I can't figure out what I'm doing wrong!

Foi útil?

Solução

Two dictionaries have equal contents if they each hold the same number of entries and, for a given key, the corresponding value objects in each dictionary satisfy the isEqual: test. This is how equaltodictionary work .so the issue looks like your contents is not holding the same number of entries. Please recheck your mutabledictinary object. And one more thing i have noticed is that your one if condition where you are comparing same dataclass in-spite of having one myclass.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top