• 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: NSRect, NSPoint, NSSize & Collections
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSRect, NSPoint, NSSize & Collections


  • Subject: Re: NSRect, NSPoint, NSSize & Collections
  • From: David Remahl <email@hidden>
  • Date: Mon, 28 Oct 2002 06:33:21 +0100

> What do you do in Cocoa when you need to put a struct like NSRect or
> NSPoint into an array? These are not formal objective-C objects, so I'm
> assuming I can't shove them into an NSArray (although correct me if I'm
> wrong in that assumption).
>
> I see a couple of options. I could use the Foundation functions
> NSRectFromString and NSStringFromRect and store them as an NSString,
> but it seems like there might be a performance penalty with this. My
> application isn't overly performance-sensitive, but...
>
> I could also use the Java approach of creating "wrapper" objects (e.g.
> in Java you store a float in a collection using Float, and int using
> Integer, etc.). It seems like this would add some overhead and possibly
> have a performance impact as well.
>
> Can someone clue me in as to which of the above methods is better, or
> if there's another option that I've overlooked?

A third alternative which is somewhere inbetween the two you suggest, is
using the following methods (defied in NSGeometry.h):

@interface NSValue (NSValueGeometryExtensions)

+ (NSValue *)valueWithPoint:(NSPoint)point;
+ (NSValue *)valueWithSize:(NSSize)size;
+ (NSValue *)valueWithRect:(NSRect)rect;

- (NSPoint)pointValue;
- (NSSize)sizeValue;
- (NSRect)rectValue;

@end

I have not analyzed the performance implications of any of those methods,
but I think either the pure wrapper class, or the one I suggest are the best
options.

/ Regards, David
_______________________________________________
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: 
 >NSRect, NSPoint, NSSize & Collections (From: Jeff LaMarche <email@hidden>)

  • Prev by Date: NSRect, NSPoint, NSSize & Collections
  • Next by Date: Re: [ANN] Cocoa Developer Meeting Place
  • Previous by thread: NSRect, NSPoint, NSSize & Collections
  • Next by thread: Re: NSRect, NSPoint, NSSize & Collections
  • Index(es):
    • Date
    • Thread