IOS 64-bit programming

Source: Internet
Author: User

1. Reject basic data types and implicit conversions 1) basic data types

Under 64 bits, the base type long takes 4 bytes to occupy 8 bytes. Take a look at where the sizeof function appears in the program, and be careful not to use the base data type, instead of the object type:

    • Nsinteger int
    • 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);}

Array. The count return value type is Nsuinteger, but when compared here with I, if I is -1,-1 is implicitly converted to a large positive integer, resulting in an error in the calculation. Be sure to pay attention to all operations associated with this variable (assignment, comparison, conversion)

This changes the base data type to Nsuinteger and the initial value starts at 0. For example, it is easier to traverse or use for-in or block.

2. Using the new enumeration
typedef ns_enum (Nsinteger, Uiviewanimationcurve) {    uiviewanimationcurveeaseinout,    Uiviewanimationcurveeasein,    uiviewanimationcurveeaseout,    uiviewanimationcurvelinear};

  

3. Replace the format string

1) unsigned long type to NSNumber:

(unsigned long)items.count 改为NSNumber@语法糖: @(items.count).

2) int type goes to string:

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

32-bit, BOOL is defined as the signed char result of @encode (BOOL) is‘c‘
64-bit, BOOL is defined as bool the @encode (bool) result is‘B‘

5. Do not take the ISA pointer directly

The compiler has disabled this use by default, the ISA pointer is the address of class under 32 bits, but using bits mask under 64 bits to remove the real address, if you really need to, use runtime object_getClass and object_setClass methods.

6. Resolve third-party Lib dependencies and Lipo commands

To add target to a arm64 compiled, Static library (. A) or framework, you need to re-locate the package that supports 64-bit.

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

Yes.

Checklist

Finally, make a list of the points of note in the official documentation:

    • Do not turn the pointer strongly into an integer
    • Unified data types are used throughout the program
    • It is important to pay attention to the operation of different types of integers.
    • When you need a fixed-length variable, use a int32_t, int64_t fixed-length type like this
    • Do not write dead size when using malloc
    • Use a formatted string that can fit two schemas at the same time
    • Note Function and function pointers (type conversions and mutable parameters)
    • Do not directly access the OBJECTIVE-C pointer (ISA)
    • Using the built-in synchronization primitives (primitives)
    • Do not hardcode the virtual memory page size
    • Go Position Independent

Reference article:

http://ios.jobbole.com/81561/

IOS 64-bit programming

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.