Question

Before I start I want to explain that I'm looking for a general solution to my inquiry, I don't have any code to show because I haven't the faintest idea of how to start. Let's say I have a program in which I have 4 buttons, two on the right (red and blue), two on the left (white and yellow). If I were to press a certain combination of buttons I want to get a specific output an example would be if I touch the red button and then the white one the word "cow" appears or if were to touch the white one then the red one the word "chicken" appears. Is there any documentation that anyone knows of that can help me with my problem? Can this even be done with an array?

Was it helpful?

Solution

HotLicks has a valid answer, but I think an NSDictionary is a better solution. Create keys based on button presses, like:

@{ @"RedWhite" : @"Cow",
      @"WhiteRed" : @"Chicken" };

Your code will be easier to read, and you can support three presses easily (assuming you're working with a timer that you invalidate after each press) by just adding another key; no recalculating your array:

 @{ @"RedWhiteBlue" : @"America" };
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top