Hacer que los archivos más antiguos sean compatibles con ARC iOS

In order to make older files capable to compiled under ARC, set the switch -fno-objc-arc under Build phase.

But only .m files listed which I can add -fno-objc-arc.

but I have some .h files that caused ARC errors too. I need to set that switch to those .h files. but I don't see them under Build phase.

So, how do I set the switch for the .h files?

Here's a sample of .h file

__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;



 /** 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)

/** 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) 
            {//minimum capacity of 1, with 0 elements the array would be free'd by realloc

            arr->arr = (id*) realloc(arr->arr,newSize * sizeof(id) );
            NSCAssert(arr->arr!=NULL,@"could not reallocate the memory");

(id*) causing the issue.

preguntado el 01 de julio de 12 a las 06:07

You shouldn't have ARC errors in the .h files if the .m has the -fno-objc-arc flag. -

there are some .h files have no corresponding .m files. -

Even if they have no .m files with a matching name, I would expect they need an #include/#import into a real source file to be part of the compilation. No? -

well, it's another B.h file imported that A.h file that has the ARC issue. I put the switch on the B.m file. -

I'am not sure if this is really related, but take a look to this question: stackoverflow.com/questions/7308090/…. -

1 Respuestas

Can you split the .h file into an .h/.m pair of files? That way, you can put the method bodies in the .m file, compile it with -fno-objc-arc, and include the .h file at will.

Respondido 01 Jul 12, 21:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.