Question

I have an NSMutableArray of playing cards. For brevity, I'll just show the objects in the suit of clubs, but all 52 cards are present in this array.

deckOfCards = [[NSMutableArray alloc] initWithObjects:
         @"AC",
         @"2C",
         @"3C",
         @"4C",
         @"5C",
         @"6C",
         @"7C",
         @"8C",
         @"9C",
         @"10C",
         @"JC",
         @"QC",
         @"KC",...nil];

I need to assign each of these objects their corresponding numerical value (i.e., A = 1, J = 10, etc.), but preferably without stripping the suit identifiers (such as "C" for clubs) off of the objects. As an extra obstacle, there is a shuffling method which is required (which uses the code found here), which I think would prevent making a second array of the proper numbers to check against the main array.

Is there a method to check for a specific object in an array, and set a numerical value for it? (similar to setting tags for elements in Interface Builder) Is my approach correct?

Thanks.

Was it helpful?

Solution

Personally, I would make a Card class, and that class would have properties for the numerical value and the suit. Then, you can just add those cards to the array. Shuffling simply uses the indexes of the array, so there no need to worry messing up that part of it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top