При обновлении приведенного ниже кода для использования автоматического подсчета ссылок для iOS 5 возникает ошибка, когда "state-> itemPtr" назначается буфер при попытке выполнить быстрое перечисление, чтобы реализующий класс можно повторять с помощью цикла "foreach". Я получаю сообщение об ошибке: «Назначение '__autoreleasing id *' на '__unsafe_unrehibited id *' изменяет свойства сохранения / освобождения указателя». Смотрите строку кода с комментарием.
/*
* @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;
}
Переменная _tuples в этом примере является переменной экземпляра типа NSMutableArray.
Как устранить эту ошибку?