2011-06-05 130 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