• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSPointerArray compact
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPointerArray compact


  • Subject: Re: NSPointerArray compact
  • From: Graham Cox <email@hidden>
  • Date: Fri, 27 Jul 2012 11:25:53 +1000

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 (email@hidden)

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:

This email sent to email@hidden

References: 
 >NSPointerArray compact (From: James Maxwell <email@hidden>)

  • Prev by Date: cocoa plugin in widget on 10.8 - is spctl a solution?
  • Next by Date: iOS4.3 simulator with Xcode 4.4
  • Previous by thread: NSPointerArray compact
  • Next by thread: cocoa plugin in widget on 10.8 - is spctl a solution?
  • Index(es):
    • Date
    • Thread