• 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: Help in 2 Diamensional Array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help in 2 Diamensional Array


  • Subject: Re: Help in 2 Diamensional Array
  • From: Andy Lee <email@hidden>
  • Date: Sat, 1 Apr 2006 19:43:45 -0500

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:
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>)

  • Prev by Date: Program responding to events
  • Next by Date: Re: String memory leak
  • Previous by thread: Re: Help in 2 Diamensional Array
  • Next by thread: Re: memory problem, advice needed
  • Index(es):
    • Date
    • Thread