Note that there are some explanatory texts on larger screens.

plurals
  1. POupdating to ARC errors
    primarykey
    data
    text
    <p>I am trying to update a project to ARC. Though I've seen a few posts on updating to ARC, none of the posts I've seen handle this specific issue. I've got multiple errors, most saying:</p> <pre><code>ARC Issue Pointer to non-const type 'id' with no explicit ownership </code></pre> <p>pointing to line </p> <pre><code>CCARRAY_FOREACH(children_, item) </code></pre> <p>in the CCMenu.m class. Please help.</p> <p><strong>Updated:</strong></p> <p>After restarting Xcode the above issue is no longer found at </p> <pre><code>CCARRAY_FOREACH(children_, item) </code></pre> <p>but was found in the ccCArray.h class at the lines I've commented as </p> <pre><code>// Arc Issue </code></pre> <p>Several other errors have surface. The warning sign:</p> <pre><code>Arc Issue Destination for this '_builtin__memmove_chk' call is a pointer to ownership-qualified-type 'autoreleasing-id' </code></pre> <p>appears wherever is memmove called in the code.</p> <p>another error:</p> <pre><code>ARC Casting Rules Implicit conversion of C pointer type 'void *' to Objective-C pointer type 'id' requires a bridged cast </code></pre> <p>appears at the lines I've commented as:</p> <pre><code>//ARC Casting Rules </code></pre> <p>ccCArray.h:</p> <pre><code>#ifndef CC_ARRAY_H #define CC_ARRAY_H #import &lt;Foundation/Foundation.h&gt; #import &lt;stdlib.h&gt; #import &lt;string.h&gt; #pragma mark - #pragma mark ccArray for Objects // Easy integration #define CCARRAYDATA_FOREACH(__array__, __object__) \ __object__=__array__-&gt;arr[0]; for(NSUInteger i=0, num=__array__-&gt;num; i&lt;num; i++, __object__=__array__-&gt;arr[i]) \ typedef struct ccArray { NSUInteger num, max; id *arr; // Arc Issue } 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) ); // Arc Issue arr-&gt;num = 0; arr-&gt;arr = (id*) malloc( capacity * sizeof(id) ); arr-&gt;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-&gt;arr); free(arr); } /** Doubles array capacity */ static inline void ccArrayDoubleCapacity(ccArray *arr) { arr-&gt;max *= 2; id *newArr = (id *)realloc( arr-&gt;arr, arr-&gt;max * sizeof(id) ); // Arc Issue // will fail when there's not enough memory NSCAssert(newArr != NULL, @"ccArrayDoubleCapacity failed. Not enough memory"); arr-&gt;arr = newArr; } /** Increases array capacity such that max &gt;= num + extra. */ static inline void ccArrayEnsureExtraCapacity(ccArray *arr, NSUInteger extra) { while (arr-&gt;max &lt; arr-&gt;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-&gt;max &gt; arr-&gt;num &amp;&amp; !(arr-&gt;num==0 &amp;&amp; arr-&gt;max==1)) { if (arr-&gt;num!=0) { newSize=arr-&gt;num; arr-&gt;max=arr-&gt;num; } else {//minimum capacity of 1, with 0 elements the array would be free'd by realloc newSize=1; arr-&gt;max=1; } arr-&gt;arr = (id*) realloc(arr-&gt;arr,newSize * sizeof(id) ); // Arc Issue NSCAssert(arr-&gt;arr!=NULL,@"could not reallocate the memory"); } } /** Returns index of first occurence of object, NSNotFound if object not found. */ static inline NSUInteger ccArrayGetIndexOfObject(ccArray *arr, id object) { for( NSUInteger i = 0; i &lt; arr-&gt;num; i++) if( arr-&gt;arr[i] == object ) return i; return NSNotFound; } /** Returns a Boolean value that indicates whether object is present in array. */ static inline BOOL ccArrayContainsObject(ccArray *arr, id object) { return ccArrayGetIndexOfObject(arr, object) != NSNotFound; } /** Appends an object. Bahaviour undefined if array doesn't have enough capacity. */ static inline void ccArrayAppendObject(ccArray *arr, id object) { arr-&gt;arr[arr-&gt;num] = [object retain]; arr-&gt;num++; } /** Appends an object. Capacity of arr is increased if needed. */ static inline void ccArrayAppendObjectWithResize(ccArray *arr, id object) { ccArrayEnsureExtraCapacity(arr, 1); ccArrayAppendObject(arr, object); } /** Appends objects from plusArr to arr. Behaviour undefined if arr doesn't have enough capacity. */ static inline void ccArrayAppendArray(ccArray *arr, ccArray *plusArr) { for( NSUInteger i = 0; i &lt; plusArr-&gt;num; i++) ccArrayAppendObject(arr, plusArr-&gt;arr[i]); } /** Appends objects from plusArr to arr. Capacity of arr is increased if needed. */ static inline void ccArrayAppendArrayWithResize(ccArray *arr, ccArray *plusArr) { ccArrayEnsureExtraCapacity(arr, plusArr-&gt;num); ccArrayAppendArray(arr, plusArr); } /** Inserts an object at index */ static inline void ccArrayInsertObjectAtIndex(ccArray *arr, id object, NSUInteger index) { NSCAssert(index&lt;=arr-&gt;num, @"Invalid index. Out of bounds"); ccArrayEnsureExtraCapacity(arr, 1); NSUInteger remaining = arr-&gt;num - index; if( remaining &gt; 0) memmove(&amp;arr-&gt;arr[index+1], &amp;arr-&gt;arr[index], sizeof(id) * remaining ); arr-&gt;arr[index] = [object retain]; arr-&gt;num++; } /** Swaps two objects */ static inline void ccArraySwapObjectsAtIndexes(ccArray *arr, NSUInteger index1, NSUInteger index2) { NSCAssert(index1 &lt; arr-&gt;num, @"(1) Invalid index. Out of bounds"); NSCAssert(index2 &lt; arr-&gt;num, @"(2) Invalid index. Out of bounds"); id object1 = arr-&gt;arr[index1]; arr-&gt;arr[index1] = arr-&gt;arr[index2]; arr-&gt;arr[index2] = object1; } /** Removes all objects from arr */ static inline void ccArrayRemoveAllObjects(ccArray *arr) { while( arr-&gt;num &gt; 0 ) [arr-&gt;arr[--arr-&gt;num] release]; } /** Removes object at specified index and pushes back all subsequent objects. Behaviour undefined if index outside [0, num-1]. */ static inline void ccArrayRemoveObjectAtIndex(ccArray *arr, NSUInteger index) { [arr-&gt;arr[index] release]; arr-&gt;num--; NSUInteger remaining = arr-&gt;num - index; if(remaining&gt;0) memmove(&amp;arr-&gt;arr[index], &amp;arr-&gt;arr[index+1], remaining * sizeof(id)); } /** Removes object at specified index and fills the gap with the last object, thereby avoiding the need to push back subsequent objects. Behaviour undefined if index outside [0, num-1]. */ static inline void ccArrayFastRemoveObjectAtIndex(ccArray *arr, NSUInteger index) { [arr-&gt;arr[index] release]; NSUInteger last = --arr-&gt;num; arr-&gt;arr[index] = arr-&gt;arr[last]; } static inline void ccArrayFastRemoveObject(ccArray *arr, id object) { NSUInteger index = ccArrayGetIndexOfObject(arr, object); if (index != NSNotFound) ccArrayFastRemoveObjectAtIndex(arr, index); } /** Searches for the first occurance of object and removes it. If object is not found the function has no effect. */ static inline void ccArrayRemoveObject(ccArray *arr, id object) { NSUInteger index = ccArrayGetIndexOfObject(arr, object); if (index != NSNotFound) ccArrayRemoveObjectAtIndex(arr, index); } /** Removes from arr all objects in minusArr. For each object in minusArr, the first matching instance in arr will be removed. */ static inline void ccArrayRemoveArray(ccArray *arr, ccArray *minusArr) { for( NSUInteger i = 0; i &lt; minusArr-&gt;num; i++) ccArrayRemoveObject(arr, minusArr-&gt;arr[i]); } /** Removes from arr all objects in minusArr. For each object in minusArr, all matching instances in arr will be removed. */ static inline void ccArrayFullRemoveArray(ccArray *arr, ccArray *minusArr) { NSUInteger back = 0; for( NSUInteger i = 0; i &lt; arr-&gt;num; i++) { if( ccArrayContainsObject(minusArr, arr-&gt;arr[i]) ) { [arr-&gt;arr[i] release]; back++; } else arr-&gt;arr[i - back] = arr-&gt;arr[i]; } arr-&gt;num -= back; } /** Sends to each object in arr the message identified by given selector. */ static inline void ccArrayMakeObjectsPerformSelector(ccArray *arr, SEL sel) { for( NSUInteger i = 0; i &lt; arr-&gt;num; i++) [arr-&gt;arr[i] performSelector:sel]; } static inline void ccArrayMakeObjectsPerformSelectorWithObject(ccArray *arr, SEL sel, id object) { for( NSUInteger i = 0; i &lt; arr-&gt;num; i++) [arr-&gt;arr[i] performSelector:sel withObject:object]; } #pragma mark - #pragma mark ccCArray for Values (c structures) typedef ccArray ccCArray; static inline void ccCArrayRemoveAllValues(ccCArray *arr); /** Allocates and initializes a new C array with specified capacity */ static inline ccCArray* ccCArrayNew(NSUInteger capacity) { if (capacity == 0) capacity = 1; ccCArray *arr = (ccCArray*)malloc( sizeof(ccCArray) ); arr-&gt;num = 0; arr-&gt;arr = (id*) malloc( capacity * sizeof(id) ); // Arc Issue arr-&gt;max = capacity; return arr; } /** Frees C array after removing all remaining values. Silently ignores nil arr. */ static inline void ccCArrayFree(ccCArray *arr) { if( arr == nil ) return; ccCArrayRemoveAllValues(arr); free(arr-&gt;arr); free(arr); } /** Doubles C array capacity */ static inline void ccCArrayDoubleCapacity(ccCArray *arr) { ccArrayDoubleCapacity(arr); } /** Increases array capacity such that max &gt;= num + extra. */ static inline void ccCArrayEnsureExtraCapacity(ccCArray *arr, NSUInteger extra) { ccArrayEnsureExtraCapacity(arr,extra); } /** Returns index of first occurence of value, NSNotFound if value not found. */ static inline NSUInteger ccCArrayGetIndexOfValue(ccCArray *arr, void* value) { for( NSUInteger i = 0; i &lt; arr-&gt;num; i++) if( arr-&gt;arr[i] == value ) return i; return NSNotFound; } /** Returns a Boolean value that indicates whether value is present in the C array. */ static inline BOOL ccCArrayContainsValue(ccCArray *arr, void* value) { return ccCArrayGetIndexOfValue(arr, value) != NSNotFound; } /** Inserts a value at a certain position. Behaviour undefined if aray doesn't have enough capacity */ static inline void ccCArrayInsertValueAtIndex( ccCArray *arr, void *value, NSUInteger index) { NSCAssert( index &lt; arr-&gt;max, @"ccCArrayInsertValueAtIndex: invalid index"); NSUInteger remaining = arr-&gt;num - index; // last Value doesn't need to be moved if( remaining &gt; 0) { // tex coordinates memmove( &amp;arr-&gt;arr[index+1],&amp;arr-&gt;arr[index], sizeof(void*) * remaining ); } arr-&gt;num++; arr-&gt;arr[index] = (id) value; } /** Appends an value. Bahaviour undefined if array doesn't have enough capacity. */ static inline void ccCArrayAppendValue(ccCArray *arr, void* value) { arr-&gt;arr[arr-&gt;num] = (id) value; arr-&gt;num++; } /** Appends an value. Capacity of arr is increased if needed. */ static inline void ccCArrayAppendValueWithResize(ccCArray *arr, void* value) { ccCArrayEnsureExtraCapacity(arr, 1); ccCArrayAppendValue(arr, value); } /** Appends values from plusArr to arr. Behaviour undefined if arr doesn't have enough capacity. */ static inline void ccCArrayAppendArray(ccCArray *arr, ccCArray *plusArr) { for( NSUInteger i = 0; i &lt; plusArr-&gt;num; i++) ccCArrayAppendValue(arr, plusArr-&gt;arr[i]); //ARC Casting Rules } /** Appends values from plusArr to arr. Capacity of arr is increased if needed. */ static inline void ccCArrayAppendArrayWithResize(ccCArray *arr, ccCArray *plusArr) { ccCArrayEnsureExtraCapacity(arr, plusArr-&gt;num); ccCArrayAppendArray(arr, plusArr); } /** Removes all values from arr */ static inline void ccCArrayRemoveAllValues(ccCArray *arr) { arr-&gt;num = 0; } /** Removes value at specified index and pushes back all subsequent values. Behaviour undefined if index outside [0, num-1]. @since v0.99.4 */ static inline void ccCArrayRemoveValueAtIndex(ccCArray *arr, NSUInteger index) { for( NSUInteger last = --arr-&gt;num; index &lt; last; index++) arr-&gt;arr[index] = arr-&gt;arr[index + 1]; } /** Removes value at specified index and fills the gap with the last value, thereby avoiding the need to push back subsequent values. Behaviour undefined if index outside [0, num-1]. @since v0.99.4 */ static inline void ccCArrayFastRemoveValueAtIndex(ccCArray *arr, NSUInteger index) { NSUInteger last = --arr-&gt;num; arr-&gt;arr[index] = arr-&gt;arr[last]; } /** Searches for the first occurance of value and removes it. If value is not found the function has no effect. @since v0.99.4 */ static inline void ccCArrayRemoveValue(ccCArray *arr, void* value) { NSUInteger index = ccCArrayGetIndexOfValue(arr, value); if (index != NSNotFound) ccCArrayRemoveValueAtIndex(arr, index); } /** Removes from arr all values in minusArr. For each Value in minusArr, the first matching instance in arr will be removed. @since v0.99.4 */ static inline void ccCArrayRemoveArray(ccCArray *arr, ccCArray *minusArr) { for( NSUInteger i = 0; i &lt; minusArr-&gt;num; i++) ccCArrayRemoveValue(arr, minusArr-&gt;arr[i]); //ARC Casting Rules } /** Removes from arr all values in minusArr. For each value in minusArr, all matching instances in arr will be removed. @since v0.99.4 */ static inline void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr) { NSUInteger back = 0; for( NSUInteger i = 0; i &lt; arr-&gt;num; i++) { if( ccCArrayContainsValue(minusArr, arr-&gt;arr[i]) ) //ARC Casting Rules { back++; } else arr-&gt;arr[i - back] = arr-&gt;arr[i]; } arr-&gt;num -= back; } #endif // CC_ARRAY_H </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload