2011-06-05 79 views
1

我得到這個警告,我不知道如何解決它。在那裏我得到警告線是初始化使整數沒有鑄造

NSInteger thescore = [[myDictionary objectForKey:@"Score"] objectAtIndex:0]; 

如果它的確與衆不同,myDictionary是的NSDictionary

編輯:這是怎麼回事?順便說一句我的數組是一個NSMutableArray的,而不是一個NSArray的

NSInteger thescore = [[myDictionary valueForKey:@"Score"] integerValue]; 

編輯2: @Bavarious提到,我應該做到以下幾點:

int thescore = [[myDictionary objectForKey:@"Score"] integerValue]; 

回答

1

通話[someArray objectAtIndex:0]的結果是一個對象。而NSInteger是基本類型:

typedef long NSInteger; 

(CMD +在Xcode上NSInteger雙擊查看定義)

我想你實際上可能你的陣列中存儲NSNumber對象。在這種情況下,你可以做

NSNumber *thescore = [someArray objectAtIndex:0]; 
+0

+1。也可以這樣做:[[[objectEdKey:@「score」] objectAtIndex:0] integerValue];'並將結果賦給一個'NSInteger'。 – 2011-06-05 06:08:46

+0

+1 ..... Josh :) – Legolas 2011-06-05 06:09:38

+0

這是怎麼回事?順便說一句,它是一個NSMutableArray迴應答覆者。 – 2011-06-05 06:14:09

相關問題