In my app I’m using two NSMutableDictionaries. Lets call them basicDictionary and refreshDictionary.
In basicDictionary I have values, lets say
key:”1″ value:”2000″ photo:someUIImage //Lets say I want to track score of player
key:”2″ value:”1500″ photo:someUIImage2
key:”3″ value:”1500″ photo:someUIImage3
key:”4″ value:”1500″ photo:someUIImage4
key stands for player id and rest is pretty clear.
I do server api call every 20 sec to refresh score of players. Because I don’t want to load photo as well im using refresh call to bring me only player id and his actual score.
So every 20 secs I get data that I save in refreshDictionary. There are only ids and current score of that id.
refreshDictionary example:
key:”1″ value:”2500″
key:”2″ value:”2800″
key:”3″ value:”2700″
I update my tableView with new values. As you can see, I got data only for 3 players, because player 4 has deleted his profile. Now my question is, how do I update basicDictionary to remove player 4?
I know that I’m supposed tu use if (!([basicDictionary isEqualToDictionary:refreshDictionary))
however, it won’t tell me at which key they aren’t equal.
So what would you guys do? Should I iterate through both of them in nested loop? That seems to consume alot of time when dictionaries are bigger. Oh by the way, my dictionaries are always sorted same way (by players id)
My idea is, that I compare these two dictionaries in
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if (refresh)
{ //compare dictionaries and modify basicDictionary that is data source for my tableview by deleting where key doesn't match
}
this code will give you keys that changed:
NOTE: as the lookup of keys is basically jumping into a hashmap (an o1 op), you dont have to worry about the 2nd array walk you talk about
Edit: self.allKeys changed to just self — a dictionary can be enumerated already