Thanks to this question/answer Automatic Reference Counting: Error with fast enumeration I resolved a part of what makes me crazy.
However, I am still getting an error “Assigning ‘NSDictionary *__strong ‘ to ‘__unsafe_unretained id‘ changes retain/release properties of pointer“. I have read the ARC Programming Guide and the parts related to conversion of pointers but, unfortunately, I am not a good enough c programmer yet.
See the line of code with the comment. Any help will be very much appreciated. Thanks in advance.
- (NSUInteger) countByEnumeratingWithState: (NSFastEnumerationState *)state
objects: (id __unsafe_unretained *)buffer
count: (NSUInteger)bufferSize
{
if (*enumRows = [self getPreparedRow]) {
state->itemsPtr = enumRows; // Assigning 'NSDictionnary *__strong *' to '__unsafe_unretained id*' changes retain/release properties of pointer
state->state = 0;
state->mutationsPtr = &state->extra[0]; // was state->mutationsPtr = (unsigned long *) self; before
return 1;
} else {
return 0;
}
}
with this declaration in the .h file
@interface BWDB : NSObject <NSFastEnumeration> {
NSDictionary * enumRows[1];
}
This will fix it.
By the code you’ve posted this should be perfectly safe since you assign it every time before you check it. In fact there is really no need to make that an instance variable at all.
You could just do something like:
I should note that there is not much value in having an pointer[] type array of NSDictionaries. It would be far more advantageous to simply use an NSArray to hold your NSDictionaries.