is it true that the key values for NSMutableDictionary can only be strings?
I was trying to use objects, but I am getting a warning.
is it true that the key values for NSMutableDictionary can only be strings?
I was trying to use objects, but I am getting a warning.
From the docs:
In general, a key can be any object (provided that it conforms to the NSCopying protocol—see below), but note that when using key-value coding the key must be a string (see Key-Value Coding Fundamentals).
What warning are you getting?
You can use any object, but the object must implement -[NSObject hash]
, -[NSObject isEqual:]
, and the NSCopying
protocol.
If you take a look at header file of NSMutableDictionary, the add function can take id as the key:
- (void)setObject:(id)anObject forKey:(id)aKey;
- (void)removeObjectForKey:(id)aKey;
So you can use virtually anything as the key and value.