Saturday, October 30, 2010

NSDictionary & NSMutableDictionary keys

NSDictionary keys must implement NSCopying. I required a map that used an UIView as a key, which does not implement NSCopying. The solution:


UISwitch* view = [[UISwitch alloc] init];


NSMutableDictionary* controls = [[NSMutableDictionary alloc] init];

[controls setObject:value forKey:[NSValue valueWithNonretainedObject:view]];


value = [controls objectForKey:[NSValue valueWithNonretainedObject: view]];

No comments:

Post a Comment