iOS Best way to compare two NSDictionary


macrumors 68000
Original poster
Sep 8, 2006
I thought I would ask before I start to write out some code that would compare 2 NSDictonaries. I wanted to see if there is some class that would make it easier and faster.

I have 2 plists
• allClientsPlist
• selectedClientPlist

The user selects a client from the tableView and it extracts the current client from the allClientPlist and saves it to the selectedClientPlist to work with instead of the entire list of clients.

It then pushes a new view on to the stack. In the new view the user can make changes to the phone numbers and so on. When the user presses the back button to return to the previous viewController It writes the changes, if any, to the selectedClientPlist.

Now back in the first viewController again I want to compare the selectedClientPlist against the on stored in an index of the allClientPlist to see if they are identical. If not I want to replace the information for this client in the allClientsPlist.

I am going to load the client from both plists in to 2 NSDictonary and then compare their Key/Value pairs which are NSStrings.

I thought there might be something created already that I could take advantage of that would do this for me, that I don't know about yet?

I thought I would check first.



Staff member
Aug 9, 2009
How do you usually compare two objects for equality?

I usually use the isEqual: method. (Look it up in NSObject.)

So look that method up in NSDictionary's class reference doc, and see what it says.

Or just make a test program, try it, and see what happens.


macrumors 6502
Jun 19, 2009
What about declaring a boolean variable (didChange or something like that) When the user makes a change, set the value to YES. When you do whatever you do to make them equal again, set the value to NO.

Of course, I say this without knowing all the possible flow paths of your code.


macrumors 68000
Original poster
Sep 8, 2006
Thanks Chown33 That was the exact thing I was thinking of doing to compare the Strings after I loaded them in. I was unsure if there was a Class I was unaware of that that made this easy to do. As it turns out I found an even easier way that is almost what the theWatchfullOne came up with.

I just simply added a Yes or No key/pair and saved it to the client file, and if the user made changes it changed it to YES. Then when the user returned to the previous ViewController I read in the Plist and looked for the YES or NO to determine if I needed to change my master client list. There was no need to compare isEqual at this point.

Register on MacRumors! This sidebar will go away, and you'll see fewer ads.