我正在尝试使用 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 参数,但我收到错误消息:
“指向整数转换的不兼容指针将'Board *_strong”发送到'NSUInteger'类型的参数(又名'unassigned long')