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