• 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: Storing NSRect in an NSMutableArray...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Storing NSRect in an NSMutableArray...


  • Subject: Re: Storing NSRect in an NSMutableArray...
  • From: Mike Shields <email@hidden>
  • Date: Tue, 3 Sep 2002 23:23:14 -0600

On Monday, September 2, 2002, at 10:43 PM, Jiva DeVoe wrote:

Here's a problem I seem to hit more often than I'd like. I want to
create
an NSMutableArray of NSRects. The problem is, an NSRect is a struct,
It's
not a real class. So if I do this, NSMutableArray will blow up. How
do I
get around this?

Here's yet another way:

@implementation NSMutableArray (CocoaDevExtras)

+ (NSMutableArray*) nonRetainingArray
{
CFArrayCallBacks callbacks = kCFTypeArrayCallBacks;
NSMutableArray *array;

callbacks.retain = NULL;
callbacks.release = NULL;

array = (NSMutableArray*) CFArrayCreateMutable(NULL,0,&callbacks);
return [array autorelease];
}

@end

Now you can stick anything you want in there. This works because a CFMutableArray is toll-free bridged to NSMutableArray. Stick in your rect pointers. The only hassle with this is you have to maintain the memory for the rects yourself, they won't automatically go away when no one cares about them anymore.

Mike
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Storing NSRect in an NSMutableArray... (From: David P Henderson <email@hidden>)

  • Prev by Date: Drag pasteboard only working within my app?
  • Next by Date: Re: Services CMM Working in Cocoa & Carbon?
  • Previous by thread: Re: Storing NSRect in an NSMutableArray...
  • Next by thread: Output text to NSView
  • Index(es):
    • Date
    • Thread