objective c - Shared array between multiple classes -


i have array "myarr" contains objects of custom class..e.g. objs of type myclass

i need share array across multiple classes..

could please me exact code should using..

i have referred singleton patter on apple , other references, ver confusing me...so great if highlight things/code need add.

i recommend read on object delegation.

@property (nonatomic,copy) nsarray *myarr;

on other classes, implement delegate object point class, use:

nsarray *retrievedarray = [self.delegate myarr];

edit: if interested use singleton believe along way:

static myclass *obj = nil;

on class array, create class method return singleton object

+(myclass*) sharedinstance {

     if (obj) {        obj = [[self alloc]init];       } 

return obj;

}

on other classes use

nsarray *retrievedarray = [[myclass sharedinstance] myarr];

to array.

cheers.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -