Tony
Tony

Reputation: 38341

Macro for defining kvc assessors in objective-c

Is there any macro to help simplify the creation of KVC macros in Objective C? As it stands in order to create a to-many mutable KVC compliant property is extremely tedious, to define a single property it takes the following

//Code.h
@property (strong, nonatomic, readonly) NSArray *prevSearches;

//Code.m

@property (strong, nonatomic, readwrite) NSArray *prevSearches;

...

@synthesize prevSearches = _prevSearches;

- (void)prevSearches {
    return [_prevSearches copy];
}

- (void)setPrevSearches:(NSArray *)prevSearches {
    _prevSearches = [NSMutableArray arrayWithArray:prevSearches];
}

- (void)insertObject:(SavedSearch *)object inPrevSearchesAtIndex:(NSUInteger)index {
    [_prevSearches insertObject:object atIndex:index];
}

- (void)removeObjectFromPrevSearchesAtIndex:(NSUInteger)index {
    [_prevSearches removeObjectAtIndex:index];
}

That's over 20 lines to define a single property, I often have several in a particular class... Surely there's an easier way?

Upvotes: 1

Views: 210

Answers (1)

user679424
user679424

Reputation:

have you tried a sofware like accessorizer? http://itunes.apple.com/it/app/accessorizer/id402866670?mt=12 otherwise i think that a simple bash script can save your time ;)

Upvotes: 3

Related Questions