I am attempting to create a “Player” object in a differing class by initializing with an array of “Player” objects that I have in my app delegate. This code worked (and still does) with ios 4.3, but crashes (SIGABRT or exec_bad_access) with ios 5.0.
I have imported the app delegate.
Here is the code that fails:
PlaybookAppDelegate *delegate = (PlaybookAppDelegate *)
[[UIApplication sharedApplication] delegate];
Player *thisPlayer = [delegate.players objectAtIndex:index.row];
Here is the declaration in my AppDelegate:
@interface PlaybookAppDelegate : NSObject <UIApplicationDelegate>
{
NSMutableArray *players;
}
@property (nonatomic, retain) NSMutableArray *players;
here is the method that defines “index”
-(id)initWithIndexPath:(NSIndexPath *)indexPath{
if (self == [super init] ) {
index = indexPath;
}
return self;
}
indexPathis an object, not a struct, so it will be deallocated if you don’t take ownership of it. You should be able to fix this issue as such:Also, with these kinds of memory issues, it’s purely coincidence that you see the error with iOS 5. It didn’t work under iOS 4 either, you’ve just been lucky.