• 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: Newbie: basic array questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Newbie: basic array questions


  • Subject: RE: Newbie: basic array questions
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Mon, 28 Apr 2003 15:31:13 -0400

> 1. I have a set of points, each with an ID, x-coord, y-coord, and a time
> point. How can I set up a mutable array of this type and access each item
> and any of their 4 attributes?

You could subclass NSObject and establish ID, x-coord, y-coord, and time as
instance variables for your "points". Then you can add instances of your
points to the array. Note that there is a struct (not a class) called
NSPoint for holding x-y coords. So you could have three ivars: ID (an
NSString?), coordinates (NSPoint), and time (NSDate).

Another option is to have each point represented by a dictionary. The keys
would be the names of your "instance variables." Then you can add each
dictionary to an array. You'll have to convert the coordinates to NSNumber
or NSValue.


> 2. I have a 2-dimensional grid of cells, each with a relative
> location on a
> grid and an idividual value. In C this was implemented as a
> two-dimensional
> array (cell [x] [y]) with the value being stored at that x-y location. How
> can I set up a 2-D array in Obj-C?

Objective-C is a superset of C. All your C tricks work. Just remember that
objects are pointers.


>
> In each case, how would I implement this in Obj-C? What is the most
> efficient way of accessing them if there are anywhere from 1 to
> 15,000 items
> in each?

Depends. That's not a stupendously large array, so I would not spend a
whole lot of time trying to optimize at this stage. Just test some things
out and see if they work.

Jonathan
_______________________________________________
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: 
 >Newbie: basic array questions (From: "Philip D Riggs" <email@hidden>)

  • Prev by Date: Re: Newbie: basic array questions
  • Next by Date: Re: Protocols on the fly?
  • Previous by thread: Re: Newbie: basic array questions
  • Next by thread: Re: Newbie: basic array questions
  • Index(es):
    • Date
    • Thread