• 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: NSArray usage question.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArray usage question.


  • Subject: Re: NSArray usage question.
  • From: Scott Stevenson <email@hidden>
  • Date: Fri, 6 May 2005 13:39:45 -0700


On May 6, 2005, at 12:24 PM, Brian O'Brien wrote:

Is this the correct way to build and use an NSArray?


NSPoint ptArray[plist->getNPolys()]; CPoint p;

    for (i=0; i < plist->getNPolys(); ++i)
    {
        p = plist->getPoint(i);
        ptArray[i].x = p.x;
        ptArray[i].y = p.y;
    }
    NSArray *pts = [NSArray arrayWithObjects:ptArray count:i];
    NSBezierPath *path = [NSBezierPath bezierPath];
    [path appendBezierPathWithPoints:pts count:i];


This won't work because an NSArray can only contain objects, and NSPoint is a struct.

In general, the more common approach is to create an NSMutableArray, and use -add: for each object. The approach above (using a raw memory block) is faster, but comes at the expense of some safety and convenience.


- Scott

--
http://treehouseideas.com/
http://theocacao.com/ [blog]


_______________________________________________ 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: 
 >NSArray usage question. (From: "Brian O'Brien" <email@hidden>)

  • Prev by Date: Re: NSTextView drawing background
  • Next by Date: Re: NSArray usage question.
  • Previous by thread: Re: NSArray usage question.
  • Next by thread: Re: NSArray usage question.
  • Index(es):
    • Date
    • Thread