【发布时间】:2014-11-19 18:57:27
【问题描述】:
我正在尝试使用 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”类型的参数(又名“未分配长”)
【问题讨论】:
标签: objective-c nsmutablearray nsuinteger