here is my plist and code
> <plist version="1.0">
> <dict>
> <key>Title</key>
> <string>News</string>
> <key>icon</key>
> <integer>0</integer>
> </dict>
> 开发者_运维问答</plist>
int i = [dictionary objectForKey:@"icon"];
NSLog(@"%d",i);
log result is 81841904 why it not 0 ?
Corey is correct. Note the word "object" in the -objectForKey:
method; in this case, that'll indeed be an NSNumber
. What you should be doing is
int i = [[dictionary objectForKey:@"icon"] intValue];
objectForKey
returns a reference, not an integer. I believe that it's returning a NSNumber
in this case. You can get an integer value out of that.
精彩评论