View Full Version : NSMuttableArray...

Apr 5, 2011, 07:16 AM
Hi guys,

Just working on a project using the iPhone accelerometer, i seem to be struggling with a simple prob..
I am basically storing the accelerometer values into an array using a button. I am doing this several times (but all stored in SAME array).

I then have a method that checks every value with its proceeding value
if the first reading was 10 4 6 9
this method would check 10 with 4, 4 with 6 and 6 with 9.

So far this is fine, but if the accelerometer data is saved several times..
e.g. first reading = 10, 4, 6, 9
second reading = 7, 5, 2, 8

What i wanted the method to do is compare the values in the first reading then compare the values in the second reading. but the method is comparing every value with its proceeding one since all the values are in the same array.

How would i overcome this pro.

cheers in advance::

Apr 5, 2011, 07:26 AM
Post some code for us to know what you are trying to do.

You do know that the accelerometer output consists of 3 values for the X Y and Z components of acceleration, right?

See: http://www.switchonthecode.com/tutorials/iphone-tutorial-reading-the-accelerometer for example. (Google search, no experience with the tutorial).


Apr 5, 2011, 02:04 PM
You do know that the accelerometer output consists of 3 values for the X Y and Z components of acceleration, right?

Yes i am aware of the accelerometer's capability. But i am only working with the X readings for now..

The acceleration.x readings are casted into integers and saved in a stroreArray, In a button press the values are saved, when the button is pressed again different set of values are saved...

I have this code in the method i am trying to compare the values from the accelerometer reading.

int value=0;
for (int i=0;i<storeArray; i++) {
if ([[storeArray objectAtIndex:i] intValue] == x && [[storeArray objectAtIndex:i+1] intValue] == y)
[array2 replaceObjectAtIndex:position withObject:[NSNumber numberWithFloat:value]];


Apr 5, 2011, 03:44 PM
storeArray is of type NSMutableArray* ? Then why do you loop on the condition "i<storeArray"?

Apr 5, 2011, 04:28 PM
Don't assume we can read your mind.

The details of how you pull the accelerometer data out, cast it and stuff it in storeArrayay be where the problem lies.

As the last post shows you need to give us more context. How is storeArray declared?