I was wondering if the following is the best way to read and make a copy an object that may be locked by another thread?
-(NSObject*) getCopyOfActiveObjectsOfType:(Class) objectClass
{
NSMutableArray* copy = [NSMutableArray arrayWithArray:[self.activeObjects objectForKey:objectClass]];
return copy;
}
I have several methods like the following that lock the object in question to add or remove objects to the array.
-(void) addObject:(NSObject *)object toPoolOfObjects:(NSMutableDictionary*) objects
{
Class objectClass = [object class];
@synchronized (objects)
{
NSMutableArray* objectArray = [objects objectForKey:objectClass];
if(objectArray == nil)
{
objectArray = [[[NSMutableArray alloc] init] autorelease];
[objects setObject:objectArray forKey:objectClass];
}
[objectArray addObject:object];
}
}