• 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: Thomas Lachand-Robert <email@hidden>
  • Date: Fri, 6 May 2005 23:19:13 +0200


Le 6 mai 05 à 21:24, Brian O'Brien a écrit :

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];



No. You are declaring ptArray as a C-array of NSPoint: these are not objects, but simple structs. So you cannot use arrayWithObjects: which expects objects as arguments.

Also since the signature of appendBezierPathWithPoints is
- (void)appendBezierPathWithPoints:(NSPoint *)points count:(int)count
you can pass directly ptArray here. So the NSArray has no purpose.

The compiler should have warned you for these inconsistencies. It is important to always read carefully compiler's warnings.

Hope this helps,

Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet à la chose. >> Molière, Tartuffe.


_______________________________________________ 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: registerDefaults Conflict with Bindings?
  • Next by Date: Displaying HTML in an NSTextView
  • Previous by thread: Re: NSArray usage question.
  • Next by thread: Advice needed: outline view with different rows?
  • Index(es):
    • Date
    • Thread