Question

I have an NSMutableArray of custom objects which are archived via NSArchiver. I need to be able to retrieve the archive as a backup and merge it with the existing NSMutableArray in app. I need to remove duplicates between the in-app NSMutableArray and the unarchived one but the usual methods of using NSSet or using comparison via isEqual or containsObject do not work as the objects though originally equal are apparently not after archiving. I can do a nested iteration through both arrays and compare the object ivars but that seems pretty heavy handed.

Is there something I'm missing. I am somewhat new to objective-C and using NSArchiver.

No correct solution

OTHER TIPS

isEqual: and hash should be overridden in the objects you store with the NSArchiver (if they're custom), otherwise you won't be able to compare items that have been unarchived with instances that you already have.

Usually the isEqual: method has to care about all the ivars that are meaningful to the equality of two objects, even because I don't know how you think to be able to compare two objects that uses many other objects with composition without checking every of them. It's just what you have to do.

If you have class A with x, y and z ivars then usually [a1 isEqual:a2] iif [a1.x isEqual:a2.x] && [a1.y isEqual:a2.y] && [a1.z isEqual:a2.z], there is nothing strange in it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top