so i have a multi-dimensional NSMutableArray. The first Array holds info such as username, password, first name, last name and email address.
NSMutableArray *newUser = [[NSMutableArray alloc]init];
[newUser addObject:username];
[newUser addObject:password];
[newUser addObject:firstName];
[newUser addObject:lastName];
[newUser addObject:emailAddress];
int localUserID = 0;
This array is then added to an array with all other users.
NSMutableArray *userArray = [[NSMutableArray alloc]init]; // app crash occurs on this line.
[userArray insertObject: newUser atIndex:localUserID];
localUserID++;
so my basic question is, why does the NSMutableArray not like to work with the
atIndex:
line but it works fine if i use
[userArray addObject:newUser];
I would simply user the later line, but when i add a new user it overlaps the last. Any help is much appreciated.
NSMutableArrayis representing user? Why you don't create subclass of NSObject calledUserwith propertiesusername, password, firstname, lastname, emailAddress and localUserID?[NSMutableArray new].NSCodingprotocol in your user class, and serialize to data. Or use JSON and add JSON encoding/decoding to your user class.