Re: NSRect, NSPoint, NSSize & Collections
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.