Skip to content

Instantly share code, notes, and snippets.

@beelsebob
Created August 25, 2011 13:44
Show Gist options
  • Select an option

  • Save beelsebob/1170693 to your computer and use it in GitHub Desktop.

Select an option

Save beelsebob/1170693 to your computer and use it in GitHub Desktop.
@interface MyClass : NSObject
@property (readwrite, copy) NSArray *someArray;
@end
@implementation MyClass
{
NSMutableArray *someArrayBacking;
}
- (id)init
{
self = [super init];
if (nil != self)
{
someArrayBacking = [[NSMutableArray alloc] init]
}
return self;
}
- (void)setSomeArray:(NSArray *)a
{
@synchronized(self)
{
if (a != someArrayBacking)
{
[someArrayBacking release];
someArrayBacking = [a mutableCopy];
}
}
}
- (NSArray *)someArray
{
@synchronized(self)
{
return [[someArrayBacking copy] autorelease];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment