Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode dynamically create arrays depending on user?

I'm trying to build an iphone fitness app to allow the user to first create 1 routine. then within the routine to create exercises, and within each of those exercises to create sets. I'd like to allow the user to create as many sets/routines.

My plan is to create an array within an array within an array.

The first array will hold the exercises (represented by an array). And within the exercise array will be the sets(represented by an array). And finally the set array will actually store the information.

I guess my question is, is this possible? To dynamically create arrays based on the user? I can't seem to find any information on this subject,.

like image 292
Meraj Patel Avatar asked Oct 21 '22 07:10

Meraj Patel


1 Answers

Yes, this is definitely possible: NSArray and its subclass NSMutableArray let you create and manage arrays dynamically, growing and shrinking them as needed.

Rather than using arrays of arrays of arrays, I would use special-purpose classes that hold arrays, but hide them, and present some functionality that is related to your specific application.

For example, you may want to consider creating a class for Routine and for Exercise. Routine would have methods like

-(void)addExercise:(MyExercise*)exercise;
-(MyExercise)getExerciseForIndex:(int)index;
-(void)removeExerciseAtIndex:(int)index;

and so on, with NSMutableArray serving as a storage for exercises.

like image 111
Sergey Kalinichenko Avatar answered Oct 24 '22 03:10

Sergey Kalinichenko