When should we use 'int' on iOS App based on arm64 architecture?

296 views Asked by At

What is the advantage of using 'int' on arm64 architecture?

Since Apple forces apps using arm64 on next February, and it suggests us using NSInteger, most of value we will probably be 8 bytes, like size_t, time_t, etc. And also, most apps face no memory issue. Except for adopting data from or to other APIs using 'int', it seems there are little chance we use 'int', is that right?

More questions, is using 'int' be more efficient, saving more memory than 'long' in arm64?

2

There are 2 answers

0
taskiner On

I don't think you need int for consuming API's.

You can use an NSNumber property.

@property (nonatomic, copy) NSNumber *number;

You can get Integer value of NSNumber like this:

[number intValue];
0
ospr On

You should try and stay away from using primitive data types like int, unsigned int, long, etc as their size is dependent on the current architecture of the platform. Instead you should use typedef'd datatypes like NSInteger, uint8_t, size_t as their size will always be consistent on different architectures. Then use which ever datatype is suitable for the current situation.

Note that for NSInteger and NSUInteger the size of the datatype is 32 bits on a 32-bit architecture and 64 bits on a 64-bit architecture.