I have an array of users in my app delegate, and in one of the screens I am trying to create an object to add to that array. The user attributes are only an email and a password. On the screen I have two text fields and a button. I want it so that when the button is pressed it generates a new user from what was entered into the fields and places that into the array of users in the app delegate.
Sorry learning the stack overflow interface atm. I’m working with the following code:
-(IBAction)addPerson:(id)sender:(ContactViewController *)controller
{
Person *newPerson = [Person personWithEmail:controller.usernameTextField.text password:controller.passwordTextField.text];
[self.(Truck_Tracker_AppAppDelegate *)UIApplication.sharedApplication.delegate).listPeople addObject:newPerson];
}
I think I’ve created the Person object newPerson successfully, I’m just having trouble getting it to the app delegate.
If it’s an array then it can be either a
NSArrayor aNSMutableArray.The first one is immutable, you cannot add elements to an existing
NSArray, you can just create a new one with an added element.In this first case you should do something similar to
If it’s a
NSMutableArraythen you can easily add the item by doing