int vs NSNumber vs NSInteger

后端 未结 4 1361
迷失自我
迷失自我 2021-02-02 10:09

I have a line of code that will work differently depending on the datatypes \"day\" and \"1\". I believe it is the following although I will check my source code later.

4条回答
  •  囚心锁ツ
    2021-02-02 10:42

    NSInteger is a simply an integer, NSNumber is an object where as int is a primitive data type.

    NSInteger is nothing more than a synonym for a long integer.

    If you need to store a number somewhere, use NSNumber. If you're doing calculations, loops, etc, use NSInteger, NSUInteger or int.

    You can wrap an NSInteger into an NSNumber using:

    NSNumber *NumberToStore = @(21);
    

    and get it back using:

    NSInteger retrievingInteger = [NumberToStore integerValue];
    

提交回复
热议问题