为了使旧文件能够在ARC下编译,请设置开关-fno-objc-arc 在构建阶段。
但只列出了.m文件,我可以添加-fno-objc-arc。
但我有一些.h文件也导致了ARC错误。我需要将该开关设置为那些.h文件。但是我没有在Build阶段看到它们。
那么,如何设置.h文件的开关?
以下是.h文件的示例
\
__object__=__array__->arr[0]; for(NSUInteger i=0, num=__array__->num; i<num; i++, __object__=__array__->arr[i]) \
typedef struct ccArray {
NSUInteger num, max;
id *arr;
} ccArray;
/** Allocates and initializes a new array with specified capacity */
static inline ccArray* ccArrayNew(NSUInteger capacity) {
if (capacity == 0)
capacity = 1;
ccArray *arr = (ccArray*)malloc( sizeof(ccArray) );
arr->num = 0;
arr->arr = (id*) malloc( capacity * sizeof(id) );
arr->max = capacity;
return arr;
}
static inline void ccArrayRemoveAllObjects(ccArray *arr);
/** Frees array after removing all remaining objects. Silently ignores nil arr. */
static inline void ccArrayFree(ccArray *arr)
{
if( arr == nil ) return;
ccArrayRemoveAllObjects(arr);
free(arr->arr);
free(arr);
}
/** Doubles array capacity */
static inline void ccArrayDoubleCapacity(ccArray *arr)
{
arr->max *= 2;
id *newArr = (id *)realloc( arr->arr, arr->max * sizeof(id) );
// will fail when there's not enough memory
NSCAssert(newArr != NULL, @"ccArrayDoubleCapacity failed. Not enough memory");
arr->arr = newArr;
}
/** Increases array capacity such that max >= num + extra. */
static inline void ccArrayEnsureExtraCapacity(ccArray *arr, NSUInteger extra)
{
while (arr->max < arr->num + extra)
ccArrayDoubleCapacity(arr);
}
/** shrinks the array so the memory footprint corresponds with the number of items */
static inline void ccArrayShrink(ccArray *arr)
{
NSUInteger newSize;
//only resize when necessary
if (arr->max > arr->num && !(arr->num==0 && arr->max==1))
{
if (arr->num!=0)
{
newSize=arr->num;
arr->max=arr->num;
}
else
{//minimum capacity of 1, with 0 elements the array would be free'd by realloc
newSize=1;
arr->max=1;
}
arr->arr = (id*) realloc(arr->arr,newSize * sizeof(id) );
NSCAssert(arr->arr!=NULL,@"could not reallocate the memory");
}
}
(id *)导致问题。
答案 0 :(得分:0)
你可以将.h文件拆分成.h / .m文件对吗?这样,您可以将方法主体放在.m文件中,使用-fno-objc-arc
进行编译,并随意包含.h文件。