I am looking to get an NSString value from a Text Field and add it to an array, I want to build an array with many strings in it ex: [hello, goodbye, too soon].
This is my current solution:
- (IBAction)submitButton:(id)sender {
NSMutableArray *wordArray = [[NSMutableArray alloc] init];
NSString *input = textField.text;
[wordArray insertObject:input atIndex:arrayIndex];
arrayIndex++;
}
This works for the first item in the array, but when I press submit again it reinitializes.My issue is how do I initialize the NSMutableArray to use in the button function, without having it in there so that it doesn't initialize every time. Thank you
viewDidLoadand then inside your function useself.wordArray.viewDidLoadis called only once for your viewController.viewDidLoadnow how do I useselfwith the array in the button function?- (void)viewDidLoad { [super viewDidLoad]; NSMutableArray *wordArray = [[NSMutableArray alloc] init]; }@property(weak) NSMutableArray * wordArray;then initialize it in viewDidload usingwordArray = [[NSMutableArray alloc] init];. Don't declare it insideviewDidLoaditself. ( sorry using my iPhone...)