[关闭]
@buoge 2017-08-09T14:14:37.000000Z 字数 4020 阅读 980

iOS App 支持64位

iOS


翻译看了一上午,发现前人已经总结好了:😁

http://blog.devcheng.com/2015/03/05/2015-03-05-jiang-ni-de-ios-gong-cheng-zhuan-huan-wei-zhi-chi-64wei-de-ban-ben/

如何让你的App 支持64位:

http://blog.devcheng.com/2015/03/02/2015-03-02-64-bit-transition-guide-for-cocoa-touch-yi-wen-,ru-he-rang-ni-de-app-zhi-chi-64wei/

以防万一:本地打了个包:将你的iOS 工程转换为支持64位的版本.zip449.6kB

在补充一下:iOS armv7, armv7s, arm64区别与应用32位、64位配置

http://www.jianshu.com/p/567d3b730608

支持64位另外一个补充

http://blog.sunnyxx.com/2014/12/20/64-bit-tips/

convert guide

1.Do Not Cast Pointers to Integers

32,64 关于int大小不一样,如有指针强转int需要修改

  1. int *c = something passed in as an argument....
  2. int *d = (int *)((int)c + 4); // Incorrect.
  3. int *d = c + 1; // Correct!

If you must convert a pointer to an integer type, always use the uintptr_t type to avoid truncation

2 Use Data Types Consistently

If the return type is a larger integer than the receiving variable, the value is truncated.

  1. long PerformCalculation(void);
  2. int x = PerformCalculation(); // incorrect
  3. long y = PerformCalculation(); // correct!

And in both runtime environments, the fpos_t and off_t types are 64 bits in size, so never assign them to an int type.

Enumerations Are Also Typed,枚举类型也要注意

In the LLVM compiler, enumerated types can define the size of the enumeration. This means that some enumerated types may also have a size that is larger than you expect. The solution, as in all the other cases, is to make no assumptions about a data type’s size. Instead, assign any enumerated values to a variable with the proper data type.

项目中枚举类型,一般数量都很少,32,64 不会超出范围

Common Type-Conversion Problems in Cocoa Touch,数据类型转换需要注意

NSInteger changes size in 64-bit code.

  1. static const NSInteger NSNotFound = NSIntegerMax;
  2. define NSIntegerMax LONG_MAX
  3. define LONG_MAX __LONG_MAX__

CGFloat changes size in 64-bit code.

CGFloat,float,double 类型不可以混转,不然会出问题
float or a double. So use CGFloat consistently.

  1. // Incorrect.
  2. CGFloat value = 200.0;
  3. CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &value);
  4. // Correct!
  5. CGFloat value = 200.0;
  6. CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &value);

Be Careful When Performing Integer Computations

Working with Bits and Bitmasks

一定要在真机上进行测试

如果你在自己的代码中使用到了如上的方法转换,编译器可能不会给你警告或者错误,在模拟器上测试可能也不会出现问题,所以一定要在真机上进行测试。

优化内存性能,只有在需要的时候才去缓存

由于 64位 编译器的支持,64位的 App 能够运行的更快一些,但是同样,占用的内存也会大一些,为了减少内存压力,你需要对你的 App 做一些内存方面的优化。

检查缓存

64位 兼容常见问题

避免将64位的 long integer 赋值给32位的 integer
避免将64位的 指针 赋值给32位的 integer
避免因数学运算或其他操作造成 指针 和 long integer 的截断
修复因数据大小造成的字节对齐问题
确保数据在32位和64位下具有相同的内存结构
重写所有汇编代码使用64位的指令集
避免可变参数方法和不可变参数方法之间转换

-Wshorten-64-to-32 让编译器检查32位于64位问题

  1. if you modernized your project, the -Wshorten-64-to-32 compiler option was automatically enabled, so the compiler automatically warns you about many cases where a value is truncated. If you did not modernize your project, you should explicitly enable that compiler option. Optionally, you may want to include the -Wconversion option, which is more verbose, but finds more potential errors.
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注