background image

iOS 中 arc 的设置与使用

    旧工程配置 arc 方案:

1,直接在 targets->build phases 中修改 compiler Flags,是否支持 arc。添加:-fobjc-arc,就

可以让旧项目支持

arc。如果想让原来支持 arc 的不使用 arc 则添加-fno-objc-arc

    
    2,因为在 build phases 中可以改变是否支持 arc,所以应该在代码中添加判断是否支持
arc,这样不管以后.m 的 arc 是否改变,都不用再次调整代码。
 
    下面是一个.h 文件(附件中也上传了.h),整合了 arc 的各种属性、release 判断,直接
#import 在你想使用 arc 的类中即可。
#ifndef paixiu_PXISARC_h
#define paixiu_PXISARC_h
#ifndef PX_STRONG
#if __has_feature(objc_arc)
#define PX_STRONG strong
#else
#define PX_STRONG retain
#endif
#endif
#ifndef PX_WEAK
#if __has_feature(objc_arc_weak)
#define PX_WEAK weak
#elif __has_feature(objc_arc)
#define PX_WEAK unsafe_unretained
#else
#define PX_WEAK assign
#endif
#endif

#if __has_feature(objc_arc)
#define PX_AUTORELEASE(expression) expression