20

ツリーハウスのチュートリアルに従って、XCode でこの一般的な Object-C 警告メッセージが表示されます。

マイボタン機能

- (IBAction)buttonPressed:(UIButton *)sender {
    NSUInteger index = arc4random_uniform(predictionArray.count);
    self.predictionLabel.text = [predictionArray objectAtIndex:index];
}

私はNSUInteger行でそれを見ます、私はいくつかの同様のスタックオーバーフローを持っています.32ビット対64ビットの数値と型キャストについて話しているようですが、ここでそれを行う方法がわかりませんか?

私の予測配列

- (void)viewDidLoad
{
    [super viewDidLoad];
    predictionArray = [[NSArray alloc] initWithObjects:
                   @"It is certain", @"It is decidely so", @"All signs say YES", @"The stars are not aligned",
                   @"My reply is no",
                   @"It is doubtful",
                   @"Better not tell you now",
                   @"Concentrate and ask again",
                   @"Unable to answer now", nil];
// Do any additional setup after loading the view, typically from a nib.
}

ここに画像の説明を入力

4

2 に答える 2

11

私のコメントによると、ターゲットアーキテクチャに関係なく、常に32ビットの符号なし整数をarc4random_uniform()受け取り、返します。u_int32_tただし、 をpredictionArray.count返しますNSUInteger。これはtypedef、32 ビット システムと 64 ビット システムでは異なる方法で処理されます。unsigned int32ビット システムでは 32ビット ( ) unsigned long、64 ビット システムでは 64 ビット ( ) です。64 ビット システムで実行している場合NSUInteger、32 ビット整数を期待する関数に 64 ビットを渡すと、コンパイラはビットを捨てていると文句を言います。

于 2013-10-15T06:41:40.867 に答える