This is an example of how I make singletons:
Code:
static RouteData *sharedData;
+(RouteData*)sharedData{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (!sharedData) sharedData = [[RouteData alloc]init];
});
return sharedData;
}
The dispatch once token and block ensure that the singleton is only allocated once.