I have created a singleton class to keep track of my data on my iPhone app. I know singleton's only need to be instantiated once, but what is the best place to instantiate it? Should this be done in the appDelegate? I want to be able to call this singleton (which contains an NSMutableArray) from a multitude of classes so that I can have access to the array.
Here is my Class I wrote:
#import "WorkoutManager.h"
static WorkoutManager *workoutManagerInstance;
@implementation WorkoutManager
@synthesize workouts;
+(WorkoutManager*)sharedInstance {
if(!workoutManagerInstance) {
workoutManagerInstance = [[WorkoutManager alloc] init];
}
return workoutManagerInstance;
}
-(id)init {
self = [super init];
if (self) {
workouts = [[NSMutableArray alloc] init];
}
return self;
}
@end