Reputation: 174
This is a log of an NSMutableDictionary I have in my app.
{
one = (
"2013-11-15 19.47.55.jpg"
);
three = (
"2013-11-15 19.47.55.jpg"
);
"three" = (
"2013-11-15 19.45.12.jpg",
"2013-11-15 19.45.02.jpg"
);
two = (
"2013-11-15 19.42.21.jpg",
"2013-11-15 19.47.55.jpg"
);
}
I'm guessing the quotes indicate there's something different about the second "three" - but I've no idea where to start debugging this. If anyone has any suggestions where to start looking, I can elaborate, and post some source code. I'm just having trouble identifying what would be relevant at the moment.
EDIT:
@Wain and @Vlad, so I think you're right, here's the log of the classes:
2013-11-15 20:32:10.034 Last[9785:60b] one __NSCFString
2013-11-15 20:32:10.036 Last[9785:60b] three __NSCFString
2013-11-15 20:32:10.038 Last[9785:60b] three
2013-11-15 20:32:10.039 Last[9785:60b] two __NSCFString
No class.. ?
Upvotes: 0
Views: 141
Reputation: 914
It looks like one of your keys is being set with something like [myDict setValue:v forKey:[threeObj description]];
and the other one is being set with [myDict setValue:otherV forKey:@"three"];
.
After a quick test, I came up with this:
// Pretend MyFirstClass implements a custom -description
MyFirstClass *o = [[MyFirstClass alloc] init];
NSMutableDictionary *d = [NSMutableDictionary dictionary];
// We get "\"Three\""
NSString *key = [o description];
[d setObject:[NSNumber numberWithBool:YES] forKey:[key lowercaseString]];
// In another part of code you're doing something like this:
key = @"Three";
[d setObject:[NSNumber numberWithInt:1000] forKey:[key lowercaseString]];
Output:
2013-11-15 14:29:21.942 Dummy[31958:c07] {
"three" = 1;
three = 1000;
}
These are definitely two unique keys. I'd check your code to make sure nothing like this is happening. Maybe you have multiple areas where you're setting values and handling the key creation differently.
Upvotes: 3
Reputation: 3366
I'd start by checking class type for the duplicates. Can't really get duplicates other way. try printing out in debug NSStringFromClass([object class]) for each object and key in your dict.
Upvotes: 0