I am converting some code to ARC. The code looks for an element in NSMutableArray, then finds, deletes, and returns that element. The problem is that the element is immediately freed after removing "removeObjectAtIndex":
- (UIView *)viewWithTag:(int)tag { UIView *view = nil; for (int i = 0; i < [self count]; i++) { UIView *aView = [self objectAtIndex:i]; if (aView.tag == tag) { view = aView; NSLog(@"%@",view);
When I run it, I get
*** -[UIView respondsToSelector:]: message sent to deallocated instance 0x87882f0
in the second log statement.
Pre-ARC, I was careful to save the object before calling removeObjectAtIndex :, and then to automatically alert it. How to tell ARC about the same?
source share