Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

VentralChaos

macrumors newbie
Original poster
Jan 15, 2009
7
0
I'm sure this is a pretty simple answer, although I can't seem to figure out the syntax. I need an NSArray to contain the contents of a function return. (From Stanford CS193P)

Code:
+ (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides

NSArray *myPoints = [[NSArray alloc] [pointsForPolygonInRect:bounds numberOfSides:5]];

That obviously does not compile but hopefully illustrates my request
 

ghayenga

macrumors regular
Jun 18, 2008
190
0
I'm sure this is a pretty simple answer, although I can't seem to figure out the syntax. I need an NSArray to contain the contents of a function return. (From Stanford CS193P)

Code:
+ (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides

NSArray *myPoints = [[NSArray alloc] [pointsForPolygonInRect:bounds numberOfSides:5]];

That obviously does not compile but hopefully illustrates my request

You mean:
Code:
NSArray *myPoints = [[NSArray alloc] initWithArray:[pointsForPolygonInRect:bounds numberOfSides:5]];
 

VentralChaos

macrumors newbie
Original poster
Jan 15, 2009
7
0
yes, ghayenga, I can tell you understand what I mean, but your suggestion does not compile "error: 'pointsForPolygonInRect' undeclared (first use in this function)"
 

detz

macrumors 65816
Jun 29, 2007
1,051
0
Where does pointsForPolygonInRect come from? What object has that method? If that function is in a UIView object of TestView then this works fine....

NSArray *myArray = [TestView pointsForPolygonInRect:CGRectMake(0, 0, 100, 100) numberOfSides:4];

pointsForPolygonInRect, the way you have it defined above is a class function so you have to call it on a class not an object.
 

VentralChaos

macrumors newbie
Original poster
Jan 15, 2009
7
0
This are the instructions I'm using: http://cs193p.stanford.edu/downloads/Assignment3.pdf

it's part of the PolygonView class that I created, but maybe I put it in the wrong place?

I've attached my project so maybe you can get a clearer picture. As always, all help is appreciated, thanks

EDIT: sooo...I figured it out I guess. I needed to make it a part of the PolygonShape class and create some new connections and other stuff. Anyways, now it is working, however I have one tiny question. In this case, why did I need to change the method to a '-' instead of a '+' like the code was given to me? Originally it wouldn't work but as soon as I made it a '-' it worked...
 

Attachments

  • HelloPoly.zip
    21 KB · Views: 221
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.