Yi Chu Chen
Yi Chu Chen

Reputation: 1

how to get the content in NSMutableArray?

I'm a beginner in learning objective c. I want to make my iphone app do this thing:

I think the first thing I need to do is to save the Coordinate of every touch, and then to check all the coordinates in the right area or not.

I Use NSMutableArray to save the Coordinate, but I don't know how to get the content in the array.

Here is my code:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    NSMutableArray *Xarray;
    NSMutableArray *Yarray;

    Xarray=[NSMutableArray arrayWithCapacity:[touches count]];
    Yarray=[NSMutableArray arrayWithCapacity:[touches count]];


    for(UITouch *touch in touches)
    {   
        CGPoint pstart=[touch locationInView:self.view];
        [Xarray addObject:[NSNumber numberWithFloat:pstart.x]];
        [Yarray addObject:[NSNumber numberWithFloat:pstart.y]];
    }    
}

thanks very much!

Upvotes: 0

Views: 188

Answers (1)

Gareth McCaughan
Gareth McCaughan

Reputation: 19981

NSMutableArray is a subclass of NSArray, whose documentation is at https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/cl/NSArray where you'll find, e.g., that the method for accessing an element in an array is called objectAtIndex:. So, e.g., Xarray objectAtIndex:0 gets the first element in the array. There are also methods for extracting multiple elements at once, iterating over all the objects in the array, etc.

For your application you might actually want indexOfObjectPassingTest: (the test would be looking for positions within a given area).

Upvotes: 1

Related Questions