Here is my singleton code:
@synthesize listOfSites;
+ (id)sharedInstance
{
static dispatch_once_t dispatchOncePredicate = 0;
__strong static id _sharedObject = nil;
dispatch_once(&dispatchOncePredicate, ^{
_sharedObject = [[self alloc] init];
});
return _sharedObject;
}
-(id)init
{
self = [super init];
if (self) {
listOfSites = [[NSMutableArray alloc] init];
}
return self;
}
@end
It’s pretty much textbook… however, I want to add another array, similiar to “listOfSites” (call it “listOfReadings”). The code that says “if (self)” confuses me.
How do I add another array to this code?
if (self) {does nothing but to verify that the[super init]has worked – and that it hasn’t returnNULLor anything…Other than that, you can do this normally, like :
listOfReadingsarray (as an ivar/property?)set it up
or
or (if it’s a
property)Example :
after having declared the new
NSMutableArrayin your.hfile :