简体   繁体   中英

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

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?

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];

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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