While updating the code below to use Automatic Reference Counting for iOS 5, an error is occurring when the "state->itemPtr" is assigned the buffer when trying to perform Fast Enumeration so that the implementing class can be iterated with the "foreach" loop. The error I am getting is "Assigning '__autoreleasing id *' to '__unsafe_unretained id*' changes retain/release properties of pointer". See the line of code with the comment.
/*
* @see http://cocoawithlove.com/2008/05/implementing-countbyenumeratingwithstat.html
* @see http://www.mikeash.com/pyblog/friday-qa-2010-04-16-implementing-fast-enumeration.html
*/
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState *)state objects: (id *)buffer count: (NSUInteger)bufferSize {
NSUInteger arrayIndex = (NSUInteger)state->state;
NSUInteger arraySize = [_tuples count];
NSUInteger bufferIndex = 0;
while ((arrayIndex < arraySize) && (bufferIndex < bufferSize)) {
buffer[bufferIndex] = [_tuples objectAtIndex: arrayIndex];
arrayIndex++;
bufferIndex++;
}
state->state = (unsigned long)arrayIndex;
state->itemsPtr = buffer; // Assigning '__autoreleasing id *' to '__unsafe_unretained id*' changes retain/release properties of pointer
state->mutationsPtr = (unsigned long *)self;
return bufferIndex;
}
The _tuples variable in this example is an instance variable of type NSMutableArray.
How do I resolve this error?