creating single array as a data source from different scene in iOS using Objective C -
i trying develop ios app has different scene of them sharing single data source nsmutablearray (dataarray). possible modify ie add / delete items array of different scenes.
note:
i know how modify/add/delete array single scene (viewcontroller ui).
simply create singleton class similar this... i.e if using arc.
myglobaldata.h
@interface myglobaldata : nsobject { nsmutablearray *mydata; } @property (nonatomic, retain) nsmutablearray *mydata; + (id)sharedmanager; @end
myglobaldata.m
@implementation myglobaldata @synthesize mydata; + (id)sharedmanager { static myglobaldata *shareddata = nil; @synchronized(self) { if (shareddata == nil) shareddata = [[self alloc] init]; } return shareddata; } - (id)init { if (self = [super init]) { mydata = [[nsmutablearray alloc] init]; } return self; } - (void)dealloc {} @end
your scene controller
-somemethod() { myglobaldata *sharedobject = [myglobaldata sharedmanager]; }
your scene n controller
-somemethod() { myglobaldata *sharedmanager = [myglobaldata sharedmanager]; }
note: can use gcd in sharedmanager i'll leave you. figure out. implementation bit different if not using arc in project.
Comments
Post a Comment