Converting int to NSInteger [duplicate]

江枫思渺然 提交于 2019-12-03 05:41:55

问题


Possible Duplicate:
How to convert An NSInteger to an int?

I am new to iOS programming, how do I convert int to NSInteger. I have found references on how to convert NSInteger to NSNumber but I wasn't able to figure it out. Any help would be appreciated. Thanks.


回答1:


An improved answer

On 64-bit systems NSInteger is long. On 32-bit systems NSInteger is int. https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Cocoa64BitGuide/64BitChangesCocoa/64BitChangesCocoa.html

All you need just cast your int to NSInteger.

int i = 1;
NSInteger nsi = (NSInteger) i;

You can also cast NSInteger to int (as in an original answer), but you must be careful on 64-bit system, because your NSInteger can exceed int limits.

An original answer

int i;
NSInteger nsi = 1;
i = nsi;

No big science. :)



来源:https://stackoverflow.com/questions/8226447/converting-int-to-nsinteger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!