I have a sharedInstance which consists of many NSMutableArrays which holds all my form data that is spread across many views in my App.
An example of their declaration in .h looks like
@property (atomic, retain) NSMutableArray *i_date;
@property (atomic, retain) NSMutableArray *i_tailNumber;
@property (atomic, retain) NSMutableArray *i_pic;
@property (atomic, retain) NSMutableArray *i_sic;
and in .m (- init)
self = [super init];
_i_date = [NSMutableArray array];
_i_tailNumber = [NSMutableArray array];
_i_pic = [NSMutableArray array];
_i_sic = [NSMutableArray array];
The shared instance function is
+(id) sharedInstance
{
static id sharedInstance = nil;
if (sharedInstance == nil) {
sharedInstance = [[self alloc] init];
}
return sharedInstance;
}
EDIT:
I instantiate all the arrays with an empty string on the first view as seen below
[_fd.i_date addObject:@""];
[_fd.i_tailNumber addObject:@""];
Finally I interact with my data this way in the prepare for segue function
[_fd.i_date replaceObjectAtIndex:leg withObject:transferDate];
rinse and repeate
My problem, which I've spent many hours investigating today by reading various blogs, the documentation, and all the wonderful resources here at SO, is that my arrays lose any objects I place in them when I segue to another view.
When I hit the code line above, I get the classic
signal SIGABRT
error, which complains that my arrays are empty (0 objects), so it cannot replace anything.
I suspect I'm not handling my shared instance properly and that ... maybe, perhaps, multiple instances of my arrays are being allocated, but I'm certain that I'm turned around in my understanding.
Any ideas what is occurring? I think I provided all the necessary code snippets but if I forgotten something just ask. Thanks again!
Jesse
EDIT: You guys are FAST! :D I created my OBJ-C file with ARC enabled, so I think I am using it. I'm a C++ guy, mostly so this optional hand holding mem stuff is natively ambiguous to me.
EDIT: The complete error is
2013-04-10 20:25:03.239 ProjectName[4230:c07] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM replaceObjectAtIndex:withObject:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x1caf012 0x10ece7e 0x1c65ba9 0x7c7e 0x478b87 0x478c14 0x1100705 0x342c0 0x270a64 0x1100705 0x342c0 0x34258 0xf5021 0xf557f 0xf46e8 0x63cef 0x63f02 0x41d4a 0x33698 0x1c0adf9 0x1c0aad0 0x1c24bf5 0x1c24962 0x1c55bb6 0x1c54f44 0x1c54e1b 0x1c097e3 0x1c09668 0x30ffc 0x222d 0x2155)
libc++abi.dylib: terminate called throwing an exception