简体   繁体   English

NSNumber到NSInteger的范围从2到528839664

[英]NSNumber to NSInteger going from 2 to 528839664

I am reading a bunch of NSNumber values from a plist, and the first line in the code I'm showing you has the value of 2 for stoneOne[@"Column"]. 我正在从一个plist中读取一堆NSNumber值,并且在代码中显示的第一行中,stoneOne [@“ Column”]的值为2。 When I set a breakpoint for 'c' in the second line, and examine [c intValue], c is correctly int 2. However, when I analyze the value of NSInteger column, the value is 528839664. Any reason for this? 当我在第二行中为'c'设置断点并检查[c intValue]时,c正确地是int2。但是,当我分析NSInteger列的值时,该值为528839664。这是什么原因? Should I just not get the intValue of c? 我是否应该不获取c的intValue? Is it necessary? 有必要吗? (I thought for converting NSNumber values to readable NSInteger values you had to call that method). (我认为要将NSNumber值转换为可读的NSInteger值,必须调用该方法)。

    NSNumber* c = stoneOne[@"Column"];
    NSInteger column = [c intValue];

Ok, Two things. 好,两件事。

As Eiko Pointed out, you need to go to the next line, to ensure the assignment like NSInteger column = [c intValue]; 正如Eiko指出的那样,您需要转到下一行,以确保分配类似于NSInteger column = [c intValue]; is executed. 被执行。 Just go one step ahead, or put the breakpoint in the line below it. 只需向前走一步,或将断点放在它下面的行中即可。

Secondly, use NSInteger column = [c integerValue]; 其次,使用NSInteger column = [c integerValue]; to optimally convert to NSInteger. 最佳地转换为NSInteger。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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