Do like this, hope this helps u :)
// in BadholmenStore.h
#import <Foundation/Foundation.h>
@interface BadholmenStore : NSObject
{
NSMutableArray *allBadholmen; //for your shared object contains one "mutable array", define it hear
}
+ (BadholmenStore *)sharedStore; //your class method
//instance methods
- (void)createBadholmen;
- (void)emptyArray;
- (NSMutableArray *)allBadholmen;
@end
// in BadholmenStore.m
#import "BadholmenStore.h"
#import "Dish.h"
@implementation BadholmenStore
static BadholmenStore *sharedStore = nil; //it shoud be visible to all, put this line hear
+ (BadholmenStore *)sharedStore
{
if (!sharedStore)
sharedStore = [[super allocWithZone:nil] init];
return sharedStore;
}
#pragma mark - tillägg av platser
- (void)createBadholmen
{
Dish *bhvar = [[Dish alloc] initWithName:@"Varierande meny"
ingredients:@" "
price:@" "];
[allBadholmen addObject:bhvar];
Dish *bhsom = [[Dish alloc] initWithName:@"Sommarlunch med varierande meny (endast sommartid)" ingredients:@"inkl. måltidsdryck" price:@"79:-"];
[allBadholmen addObject:bhsom];
}
- (void)emptyArray
{
[allBadholmen removeAllObjects];
}
- (NSMutableArray *)allBadholmen // replace your NSArray with NSMutableArray
{
return allBadholmen;
}
#pragma mark - Overriden methods
+ (id)allocWithZone:(NSZone *)zone
{
return [self sharedStore];
}
- (id)init
{
self = [super init];
if (self) {
allBadholmen = [[NSMutableArray alloc] init];
}
return self;
}
@end
//in the class where u are using this shared class object
[super viewDidLoad];
[[BadholmenStore sharedStore] emptyArray];
[[BadholmenStore sharedStore] createBadholmen];
NSMutableArray *allObjects = [[BadholmenStore sharedStore] allBadholmen]; // now use allObjects