views:

193

answers:

1

I have ten buttons that each correspond to a different number. I'm looking to record the order that these buttons are pressed and enter them into an array and then compare it to another array that is static in the app. The check should be done on the Nth button press, where N equals the number of items in the other, static array.

How do I A) have a button press add a value to an array B) stop after Nth button press equal to amount of numbers in the array I'm checking against and C) compare this array to the other array?

A: 

You could:

  1. Decide on N and create an array with your N numbers as NSNumber objects (NSArray and NSMutableArray require objects).

  2. Link the buttons to an action.

  3. In the action method, check the first parameter against each button to determine which number was pressed.

  4. Add that number to a mutable array.

  5. When the array's size is equal to N, do your check: use a for loop from 0 to N-1 and get the objects at that index from each array. Compare them using isEqual:. If any comparison fails, then you know that the arrays don't match. Otherwise, you have success.

gerry3