将字符串中的数据存储到整数数组中

时间:2011-04-17 04:27:49

标签: objective-c arrays ios

我在字符串中有一些数据,我希望将这些数据存储在整数数组中......以下是代码。

int valMines[256];

// 'b' is NSString with 256 values in it.
for(int i=0; i<[b length]; i++){
valMines[i] =  [NSString stringWithFormat:@"%d", [b characterAtIndex:i]];

NSLog(@"valMines1 is %@", valMines[i]);
}

我收到警告,因为我的应用程序没有加载: 赋值在没有强制转换的情况下从指针生成整数。

请帮忙

1 个答案:

答案 0 :(得分:1)

你的valMins是一个整数数组,你正在为它分配NSString。可能你看起来像这样:

unichar valMines[256];  // make it unichar instead of int

// 'b' is NSString with 256 values in it.
for(int i=0; i<[b length]; i++){
    valMines[i] =  [b characterAtIndex:i]; // get and store the unichar

    NSLog(@"valMines1 is %d", valMines[i]);  // format specifier is %d, not %@
}