开发者

a problem when get Number type in Dictionary (iPhone)

开发者 https://www.devze.com 2022-12-18 00:32 出处:网络
here is my plist and code > <plist version=\"1.0\"> ><dict> ><key>Title</key>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消