I want to build a shared object that all the classes will be able to access to it.
i want that in this object will be NSMutableArray .
this is how i call this object
+(id)sharedManager{
@synchronized(self) {
if (sharedManager == nil){
sharedManager = [[self alloc] init];
array = [[NSMutableArray alloc] init];
}
}
return sharedManager;
}
and this is how i define the NSMutableArray :
@property (nonatomic,retain) NSMutableArray *array;
the problem is that after i create this NSMutableArray in the sharedManager method, every time i try to access the array is equal to Nil.
@synchronizedblock to protect an action that should only occur once. Replace that with a call todispatch_once()instead. It's cleaner and faster.arraydeclared? They way you're doing it it has to be declared static, and would not be accessible from a property. You can make the propertyreadonlyand write your owngetArraymethod rather than using@synthesize, however, to make it accessible from the property.