Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help in 2 Diamensional Array



On Apr 1, 2006, at 12:53 PM, William Bumgarner wrote:
@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding>
- (unsigned)count;
- (id)objectAtIndex:(unsigned)index;
@end

And:

@interface NSMutableArray : NSArray
- (void)addObject:(id)anObject;
- (void)insertObject:(id)anObject atIndex:(unsigned)index;
- (void)removeLastObject;
- (void)removeObjectAtIndex:(unsigned)index;
- (void)replaceObjectAtIndex:(unsigned)index withObject:(id)anObject;
@end

The rest of the implementation on the NSArray and NSMutableArray classes are implemented entirely in terms of those methods.
[...] In the context of the 2D array, all of the above methods could be made to do something semi-reasonable in such a context.

When I imagine the API for an Array2D class, the insert and remove methods don't make sense to have at all -- but I admit I'm jumping to conclusions about what the OP really needs; there could be all kinds of reasonable definitions for Array2D. Supporting a couple of odd methods (especially if you'll never call them directly in practice) might arguably be worth it to get things like make-perform for free.


Implementing a subclass of NSObject that offers a 2D array of objects would be straightforward, as well.

If you're just talking about creating a basic data structure with getters and setters, I think in fact it would be more straightforward and less error-prone than fitting a 2D API on an NSArray subclass. Most of the important implementation would not be in the class cluster methods I'd be implementing; most of it would be in the init method, where internal storage will be allocated, and in accessor methods that take two indices instead of one.


--Andy

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Help in 2 Diamensional Array (From: Andy Lee <email@hidden>)
 >Re: Help in 2 Diamensional Array (From: William Bumgarner <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.