NSMutableArray を使用して、単純なコマンドラインの三目並べゲームを作成しようとしています。
メソッド「getPosition」を使用して「Board」というクラスを作成しました(これがユーザー入力を取得する最良の方法であると想定しています)位置を求めてから、intからNSUIntegerにキャストしています)
#import "Board.h"
@implementation Board
-(void)getPosition;
{
int enteredPosition;
scanf("%i", &enteredPosition);
NSUInteger nsEnteredPosition = (NSUInteger ) enteredPosition;
NSLog(@"Position = %lu", (unsigned long)nsEnteredPosition);
}
#import <Foundation/Foundation.h>
#import "Board.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSString *currentPlayer;
NSMutableArray *gameBoard=[[NSMutableArray alloc] initWithCapacity:9];
for(int i; i<=2; i++)
{
if(i %2)
{
currentPlayer=@"X";
}
else
{
currentPlayer=@"O";
}
NSLog(@"Player %@, select an open spot 1 - 9 on the board", currentPlayer);
Board *currentPosition = [[Board alloc] init];
[currentPosition getPosition];
[gameBoard insertObject:currentPlayer atIndex:currentPosition]; //this is where i have a problem
}
私が理解しているように、atIndex には NSUInteger パラメータが必要ですが、次のエラー メッセージが表示されます。
タイプ「NSUInteger」(別名「unassigned long」)のパラメーターに「「Board * _strong」を送信する整数変換への互換性のないポインター