Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't Add Object to NSMutableArray
    primarykey
    data
    text
    <p>I have a class called <code>KCBlackjack</code>. The class contains this code:</p> <pre><code>playerHand = [[NSMutableArray alloc] init]; dealerHand = [[NSMutableArray alloc] init]; blackjack = [[KCBlackjack alloc] initWithNumberOfDecks:6]; [self deal]; [blackjack dealTo:playerHand dealer:dealerHand]; </code></pre> <hr> <pre><code>- (void)dealTo:(NSMutableArray *)player dealer:(NSMutableArray *)dealer { // How many cards are left NSLog(@"Cards in Deck: %d", [_decks count]); // Deal to player then dealer for (int i = 0; i &lt;= 1; i++) { [player addObject:[_decks lastObject]]; [_decks removeLastObject]; NSLog(@"%@", player); if(_delegate &amp;&amp; [_delegate respondsToSelector:@selector(didDistributeCard:withValue:)]) { KCCard *aCard = (KCCard *)[player objectAtIndex:player.count-1]; [_delegate didDistributeCard:aCard to:player withValue:[aCard value]]; } [dealer addObject:[_decks lastObject]]; [_decks removeLastObject]; NSLog(@"%@", dealer); if(_delegate &amp;&amp; [_delegate respondsToSelector:@selector(didDistributeCard:withValue:)]) { KCCard *aCard = (KCCard *)[dealer objectAtIndex:dealer.count-1]; [_delegate didDistributeCard:aCard to:dealer withValue:[aCard value]]; } } NSLog(@"Done Dealing"); NSLog(@"Cards Remaining in Deck: %d", [_decks count]); NSLog(@"Player: %@\n\n", player); NSLog(@"Dealer: %@\n\n", dealer); } </code></pre> <p>Inside of my game controller, I set <code>player</code> to my player array as well as the dealer his. When this is run however, it doesn't work. No objects are added to the player array that player or dealer is assigned.</p> <p>When the code is in the game controller, it works, but not in this class. I figure something is not initializing, but in the game controller, the player and dealer are both initialized.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload