IOS 64-bit programming and ios64-bit Programming

Source: Internet
Author: User

IOS 64-bit programming and ios64-bit Programming
1. Reject basic data types and implicit conversions 1) Basic Data Types

In 64-Bit mode, the basic type of long is changed from 4 bytes to 8 bytes. Take a look at the sizeof function in the program, and try not to use the basic data type, instead of the object type:

  • Int-> NSInteger
  • Unsigned-> NSUInteger
  • Float-> CGFloat
  • Animation time-> NSTimeInterval
  • ...
2) implicit conversion
NSArray *items = @[<a href="http://www.jobbole.com/members/1/" rel="nofollow">@1</a>, @2, @3];for (int i = -1; i < items.count; i++) {    NSLog(@"%d", i);}

The Return Value Type of array. count is NSUInteger. However, if I is-1,-1 is implicitly converted to a large positive integer when compared with I, resulting in a computing error. Be sure to pay attention to all operations related to this variable (assignment, comparison, conversion)

Change the basic data type to NSUInteger, and the initial value starts from 0. Here is only an example. It is more convenient to use for-in or block for traversal.

2. Use the new enumeration version
typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {    UIViewAnimationCurveEaseInOut,    UIViewAnimationCurveEaseIn,    UIViewAnimationCurveEaseOut,    UIViewAnimationCurveLinear};

  

3. Replace the Format String

1) convert the unsigned long type to NSNumber:

(unsigned long) Change items. countNSNumberOf@Syntax sugar: @ (items. count ).

2) convert int type to string type:

NSInteger i = 10086;NSString *string = @(i).stringValue;
4. BOOL under 64-bit

In 32-bit, BOOL is definedsigned char, @ Encode (BOOL) the result is'c'
In 64-bit mode, BOOL is definedbool, @ Encode (BOOL) the result is'B'

5. The isa pointer is not directly obtained.

This is disabled by default by the compiler. The isa pointer is the Class address in 32 bits, but the actual address can be obtained using bits mask in 64 bits, use runtimeobject_getClassAndobject_setClassMethod.

6. Solve third-party lib dependencies and lipo commands

Add targetarm64For compiling, static library (. a) or framework, you need to find a new 64-bit package.

7. Will the package become larger after 64-bit support?

Yes.

Checklist

Note:

  • Do not convert the pointer to an integer
  • Uniform data types are used everywhere in the program
  • Be sure to perform operations on Integers of different types.
  • Useint32_t, int64_tThis type of Fixed Length
  • When using malloc, do not overwrite the size
  • Use a formatted string that can adapt to both Architectures
  • Pay attention to functions and function pointers (type conversion and variable parameters)
  • Do not directly access the Objective-C pointer (isa)
  • Use built-in synchronization Primitives (Primitives)
  • Do not hard-code the size of the VM page
  • Go Position Independent

References:

Http://ios.jobbole.com/81561/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.