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 object nsvalue , used key dictionary.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -