Well, I have no idea what is going on here. I have written an application (my first, incidentally, so this is no doubt a newbie error) that keeps falling over when trying to access an instance of NSMutableArray. The synopsis of the problem is as follows:
1. The application consists of an AppController object that is a subclass of NSObject. When the application is started the init method gets called an as part of the setup an instance of NSArray is created that is populated with a shedload of NSString objects (it's basically the data from a CSV file). The application displays a window and awaits the user to enter an integer and press a button. The instance of NSArray is sent a retain method when it is created using an accessor method.
2. When data is entered and the button pushed an IBAction method creates an instance of NSMutableArray using a NSRange within the NSArray created earlier. This object is passed as an argument to the initialisation method of a custom class.
3. When the custom class is setup it calls its superclass (another custom class) and the superclass adds the instance of NSMutableArray using an accessor method in which it is sent a retain message.
4. Following setup of the superclass and the child class that was instantiated explicitly, the child class attempts to access the contents of the NSMutableArray using an accessor method to count the number of objects and BANG!
The output from the debugger appears to suggest that the NSMutableArray object has been released somehow and I can only assume that the Autorelease has something to do with it, although I can't see how. When the NSMutableArray is added to the custom class I put a check in place to verify the retaincount and it's 2. I do not release any of my objects until it comes time for deallocation of the complete object so how is this object getting released?
What mystifies me even more here is that I am able pass to the custom class an instance of NSDictionary that, again, is handled by the superclass but yet this causes me no problems. Is there a scope issue whereby a child class cannot access an instance variable of its parent class?
This is really doing my head in so any assistance is greatly appreciated.
1. The application consists of an AppController object that is a subclass of NSObject. When the application is started the init method gets called an as part of the setup an instance of NSArray is created that is populated with a shedload of NSString objects (it's basically the data from a CSV file). The application displays a window and awaits the user to enter an integer and press a button. The instance of NSArray is sent a retain method when it is created using an accessor method.
2. When data is entered and the button pushed an IBAction method creates an instance of NSMutableArray using a NSRange within the NSArray created earlier. This object is passed as an argument to the initialisation method of a custom class.
3. When the custom class is setup it calls its superclass (another custom class) and the superclass adds the instance of NSMutableArray using an accessor method in which it is sent a retain message.
4. Following setup of the superclass and the child class that was instantiated explicitly, the child class attempts to access the contents of the NSMutableArray using an accessor method to count the number of objects and BANG!
The output from the debugger appears to suggest that the NSMutableArray object has been released somehow and I can only assume that the Autorelease has something to do with it, although I can't see how. When the NSMutableArray is added to the custom class I put a check in place to verify the retaincount and it's 2. I do not release any of my objects until it comes time for deallocation of the complete object so how is this object getting released?
What mystifies me even more here is that I am able pass to the custom class an instance of NSDictionary that, again, is handled by the superclass but yet this causes me no problems. Is there a scope issue whereby a child class cannot access an instance variable of its parent class?
This is really doing my head in so any assistance is greatly appreciated.