简体   繁体   中英

Initialization makes integer without a cast

I get this warning and I am not sure how to fix it. The line where I get the warning is

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

If it makes a difference, myDictionary is a NSDictionary

Edit: How is this? Btw my array is a NSMutableArray and not a NSArray

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

Edit 2: @Bavarious mentioned that I should do the following:

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

The result of call [someArray objectAtIndex:0] is an object. And NSInteger is a primitive type:

typedef long NSInteger;

(cmd + double-click on NSInteger in xcode to see the definition)

I guess you might actually be storing NSNumber objects in your array. In this case, you could do

NSNumber *thescore = [someArray objectAtIndex:0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM