CLBeaconRegion *region;
NSMutableDictionary *beacons;
....
beacons[region] = beacons;
Is the code above setting beacons
key as region
to the value of beacons
? I thought the key has to be a string
in a NSDictionary/NSMutableDictionary
?
CLBeaconRegion *region;
NSMutableDictionary *beacons;
....
beacons[region] = beacons;
Is the code above setting beacons
key as region
to the value of beacons
? I thought the key has to be a string
in a NSDictionary/NSMutableDictionary
?
When you say:
beacons[region] = beacons;
That's the same as:
[beacons setObject:beacons forKey:region];
The first is just syntactical shortcut for second. Either way, it's probably not what you want, since it doesn't usually make sense to set a dictionary key/value pair that points back to the dictionary itself. What are you actually trying to do?
The key in a dictionary doesn't have to be a string, but it does have to conform to the NSCopying
protocol, see the definition:
- (void)setObject:(id)anObject
forKey:(id<NSCopying>)aKey
beacons[region] = beacons;
seems to be incorrect as you are adding the beacons
dictionary to itself under the key region
.
Note that when using key-value coding the key must be a string see Key-Value Coding Fundamentals.