• 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: many-to-many relationships and retain cycles
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: many-to-many relationships and retain cycles


  • Subject: Re: many-to-many relationships and retain cycles
  • From: "Adam R. Maxwell" <email@hidden>
  • Date: Mon, 02 Jun 2008 20:29:16 -0700

On Jun 2, 2008, at 10:01 AM, Jens Alfke wrote:

On 2 Jun '08, at 9:12 AM, Todd Ransom wrote:

It seems that what I need is a non-retaining array. I googled around a bit and was surprised that I could not find an existing implementation. It looks like I can create one by subclassing NSMutableArray, overriding the primitive methods, and using a CFArray as the backing store with NULL callbacks to avoid any kind of retain or release when objects are added or removed.

You can also do cool things like store integers and NULL values in CFArray/CFDictionary/CFSet with appropriate callbacks; OmniFoundation has some predefined callbacks that can be useful examples.


It's even easier than that, thanks to CF/NS bridging. You can just use the CFArray API to create an array with no-op retain/release callbacks, and then cast the CFArrayRef to NSArray* and use it as an NSArray.

Jens alludes to using NULL retain/release, and that's a subtlety that you might want to watch out for. If you want NSArray semantics for things like indexOfObject:, you should write a callback function for equality that uses isEqual:. If you pass NULL for the callbacks, you'll get pointer equality.


--
adam
_______________________________________________

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: 
 >many-to-many relationships and retain cycles (From: Todd Ransom <email@hidden>)
 >Re: many-to-many relationships and retain cycles (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: NSPredicate: To be, or not to be
  • Next by Date: Re: trying to glue a cocoa ui to a pthread application / subclassing nsview
  • Previous by thread: Re: many-to-many relationships and retain cycles
  • Next by thread: Re: many-to-many relationships and retain cycles
  • Index(es):
    • Date
    • Thread