I'm working in objective C on xCode and I'm having a hard time solving an issue with mutable arrays. I have the following method in my main view controller .m file
- (IBAction)addData:(UIButton *)sender {
double x = [_xField.text doubleValue];
double y = [_yField.text doubleValue];
[inputXData addObject:[NSNumber numberWithDouble:x]];
[inputYData addObject:[NSNumber numberWithDouble:y]];
}
which takes the input fields xField and yField and adds their input values to arrays inputXData and inputYData.
I'd like to declare inputXData and inputYData as an NSMutableArray so that they're accessible to this method (and so I can add to them or remove from them at will eventually), but I know initializing them in this method every time it runs would make no sense.
Where should I initialize these arrays? Should I write special methods to initialize them? If so, what should I name them and where should I put them?
Also, I'd like inputXData and inputYData to be available in other views later. Will I need extra work to make sure I keep these arrays between views?