I don't believe there is a compiler flag that will help you, however you could change the semantics of your array access so it goes through your own methods instead of directly to the NSMutableArray
.
So instead of
@interface MyClass : NSObject
@property NSMutableArray *array
@end
use:
@interface MyClass : NSObject
- (void)addObject:(id)object;
- (NSUInteger)objectCount;
- (id)objectAtIndex:(NSUInteger)index;
- (void)removeObjectAtIndex:(NSUInteger)index;
@end
and you can add whatever checks you like to those array access methods (as well as lazily creating the array, of course).
However, as you can see, this could be add significant effort just to solve a small issue, and I wouldn't do this myself :)