On 27/07/2012, at 10:33 AM, James Maxwell wrote: > I'm using NSPointerArrays to store references for a complex object graph. The > nodes themselves are stored in an NSDictionary for archiving, and the pointer > arrays are just used to record the interconnectivity of the nodes (it's loopy > and complex, which has been causing problems with NSKeyedUnarchiver). What > I'm finding is that I'm getting nil references in my pointer arrays after > unarchiving (which is a mystery I still have to solve), so I'd like to get > rid of the nils before using the graph. However, calling -compact on them > doesn't seem to work. No matter what I do, the nils are still in the arrays, > and I'm really not sure what else I can do to get rid of them. The objects > are instances of a custom class (i.e., not primitives) and I'm initializing > with -pointerArrayWithWeakObjects. > > Any thoughts appreciated.
One problem I've run into with NSPointerArray is that the API only allows you to recover the pointer (or remove it) by index. Since compacting changes the indexes, doing this means you lose track of the pointers unless you have some complicated means of tracking which pointer has which index, which means you need some additional data structure to do that... and basically it all ends up needlessly complex. So instead, I just don't compact the array and allow the nils to build up so the indexes remains static. I'm not archiving it though so next run I start over, and the total number of pointers is pretty small anyway. This might not have any bearing whatsoever on your problem, but I thought I'd share it anyway. It could be that -compact doesn't work (I don't know, because I don't use it for the above reason), or perhaps this is the wrong choice of container class for your case. --Graham _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com