Converting int to NSInteger

59,625

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. :)

Share:
59,625
Bala
Author by

Bala

Every day I work to improve myself and my skills — that’s part of becoming better at whatever I do. My Open Source projects mail me @ [email protected]

Updated on July 09, 2022

Comments

  • Bala
    Bala almost 2 years

    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.