I’m try to get a point based structure from a function called:
-(NSArray *) calcRose : (float) theta
{
//first calculate x and y
//we need to get width and height of uiscreen
//myPoint[0] = [UIScreen mainScreen].applicationFrame.size.width;
NSMutableArray *Points = [[NSMutableArray alloc ] arrayWithCapacity:2];
float angle = [self radians:theta];
float side = cos(n * angle);
int cWidth = 320;
int cHeight = 240;
float width = cWidth * side * sin(angle) / 2 + cWidth /2;
float height = cHeight * side * cos(angle) / 2 + cHeight /2;
[Points addObject:[NSNumber numberWithFloat:cWidth]];
[Points addObject:[NSNumber numberWithFloat:cHeight]];
NSArray *myarr = [[[NSArray alloc] initWithArray:Points ]autorelease ];
return myarr;
}
I use below code for retrieving data from the function:
NSArray *tt = [[ NSArray alloc] initWithArray:[self calcRose:3] ];
But every time I compile the program it gives me some error.
How can I solve this problem?
[[NSMutableArray alloc ] arrayWithCapacity:2]definitely is wrong. Try[NSMutableArray arrayWithCapacity:2]instead. Also, you can just use[[self calcRose:3] retain]rather than[[NSArray alloc] initWithArray:[self calcRose:3]], and you only need theretaincall if you intend to keep the array around for longer than the current runloop pass.