This behaves to an outside observer mostly like @property (copy), except it has the very nice property of automatically performing any side effects that may exist in remove<Key>AtIndexes: and insert<Key>:atIndexes:. If I'm going to have such side effects, this seems really handy (DRY!)--is there anything wrong with this strange-looking accessor method?- (void)setEdges:(NSArray *)newEdges{    if (newEdges != edges)    {        [self removeEdgesAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [edges count])]];        [edges release];        edges = nil;        if (newEdges)        {            edges = [NSMutableArray new];            [self insertEdges:newEdges atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [newEdges count])]];        }    }}
Is there anything wrong with this unusual NSMutableArray setter?
objective c;cocoa;properties
It turns out that this doesn't even achieve what I set out to do: by calling those KVO-compliant methods within a KVO-compliant method, I actually generate multiple notifications and the system turns out even less helpful than a standard accessor.I settled on this verbose but effective method:@synthesize edges;- (void)setEdges:(NSArray *)newEdges{    if (newEdges != edges)    {        [self willRemoveEdgesAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,[edges count])]];        [self willInsertEdges:newEdges atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,[newEdges count])]];        [edges release];        edges = [newEdges mutableCopy];    }}- (void)removeEdgesAtIndexes:(NSIndexSet*)indexSet{    [self willRemoveEdgesAtIndexes:indexSet];    [edges removeObjectsAtIndexes:indexSet];}- (void)insertEdges:(NSArray*)newEdges atIndexes:(NSIndexSet*)indexSet{    [self willInsertEdges:newEdges atIndexes:indexSet];    [edges insertObjects:newEdges atIndexes:indexSet];}- (void)willRemoveEdgesAtIndexes:(NSIndexSet*)indexSet{    //My side effects here}- (void)willInsertEdges:(NSArray*)newEdges atIndexes:(NSIndexSet*)indexSet{    //My side effects here}With some clever use of respondsToSelector: and performSelector:, you can even replace most of this code with a single-line preprocessor macro that automatically synthesizes all three accessors and calls your side effect methods iff you implemented them.