简体   繁体   中英

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?

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 ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM