forループ内で変数を再割り当てして別のメモリアドレスを与える方法はありますか
ARCを使用しています
コードの主要部分はここにあります。
- (void) deal:(BOOL)isDefault
{
player = [[Player alloc] init];
appDel = [[BlackjackAppDelegate alloc] init];
appDel.playersArray = [[NSMutableArray alloc] init];
appDel.discardPile = [[NSMutableArray alloc] init];
// Initial Deal
int i; // Current Card for player
int j; // Current Player
if (isDefault)
{
startingCardCount = 7;
numberOfPlayers = 4;
}
for (int temp = 0; temp < numberOfPlayers; temp++)
{
[self addPlayersWithNumber:temp];
}
// Loops through number of cards supposed to be in hand (if default settings: use 7 cards)
for (i = 0; i < startingCardCount; i++)
{
// Loop through number of players (if default settings: use 4 players)
for (j = 0; j < numberOfPlayers; j++)
{
//Player *tempPlayer = [appDel.playersArray objectAtIndex:j];
Card *card = [Card generateCardWithAppDel:appDel];
Player *tempPlayer = [appDel.playersArray objectAtIndex:j];
[tempPlayer.hand addObject:card];
[self refreshPlayerIndex:j withPlayer:tempPlayer];
}
}
}
- (void) addPlayersWithNumber:(NSInteger)playerNumber
{
// THIS VARIABLE I WANT TO "REALLOCATE" EACH TIME THIS METHOD IS CALLED
Player *tempPlayer = [[Player alloc] init];
tempPlayer.number = playerNumber;
[appDel.playersArray addObject:player];
}
あなたが私に与えることができる助けをありがとう、私は配列に追加し、取引方法の別の部分で操作しているので、これを修正する必要があります
編集:
Player.h:
//
// Player.h
// Blackjack
//
// Created by Zach Ross-Clyne on 02/03/2013.
// Copyright (c) 2013 Avicode. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "BlackjackAppDelegate.h"
@interface Player : NSObject
{
NSInteger type;
NSInteger number;
NSMutableArray *hand;
}
@property (nonatomic, strong) NSMutableArray *hand;
@property (nonatomic) NSInteger type;
@property (nonatomic) NSInteger number;
@end
Player.m
//
// Player.m
// Blackjack
//
// Created by Zach Ross-Clyne on 02/03/2013.
// Copyright (c) 2013 Avicode. All rights reserved.
//
#import "Player.h"
@implementation Player
@synthesize number, hand, type;
- (id) init
{
hand = [[NSMutableArray alloc] init];
return self;
}
@end