Try this way for correct way to make singleton:
make class let's say AppManager
In the AppManager.h file:
#import <Foundation/Foundation.h>
@interface AppManager : NSObject
@property (strong, nonatomic) NSMutableArray *privateItems;
+ (instancetype) sharedInstance;
@end
in the AppManager.m File:
#import "AppManager.h"
@implementation AppManager
@synthesize privateItems;
static id sharedInstance;
+ (instancetype) sharedInstance{
@synchronized(self){
if(sharedInstance == nil)
{
sharedInstance = [[self alloc]init];
}
}
return sharedInstance;
}
+ (void)load{
[super load];
[self sharedInstance];
}
- (id)init
{
self = [super init];
if (self) {
self.privateItems = [[NSMutableArray alloc]init];
}
}
return self;
}
@end
in your initializer:
BYFFeedItem *item9 = [[BYFFeedItem alloc] init];
item9.name =@"meal solv 44";
item9.netEnergyM = @"2.06";
item9.netEnergyG = @"1.40";
item9.crudePro = @"49.9";
item9.calcium =@"0.33";
item9.phosphorus=@".71";
AppManager *appManager = [AppManager sharedInstance];
[[appManager privateItems] addObject:item9];
NSLog(@"init the custom defualts");
When you want to call your privateItems content just make:
AppManager *appManager = [AppManager sharedInstance];
NSArray *array = [appManager privateItems];
That's it, this is the right way to make singleton ;)
Hop it's helping and understood enough.
* Don't forger to import AppManager.h file, my recommendation is to import it to your "project name"-Prefix.pch file for make it available to all your app scope, that's the idea of singleton to make it available all over the APP.