objective c - using CLLocation objects as keys in dictionary -
is possible use cllocation objects keys in dictionary? when try this, [dictionary objectforkey: cllocationobj] returns nil when there cllocation keys inserted same latitude , longitude. doing wrong?
(location *location in somearray) { cllocation *locationkey = [[cllocation alloc] initwithlatitude:[location.latitude doublevalue] longitude:[location.longtitude doublevalue]]; locationannotation *annotationatlocation = [self.uniquelocations objectforkey:locationkey]; if (annotationatlocation == nil) nslog(@"this nil"); }
i know debugging there multiple objects of location same latitude , longitude in somearray.
cllocation
not seem override isequal
perform actual content comparison, instead compares equality based on object identity. therefore not wise use key in dictionary, unless accessing using exact same object.
the solution have described in comment quite workaround many situations:
i ended converting
cllocationcoordinate2d
objectnsvalue
, used key dictionary.
Comments
Post a Comment