用于在 Objective-C 中定义 kvc 评估器的宏
是否有任何宏可以帮助简化 Objective C 中 KVC 宏的创建?就目前情况而言,创建一个多可变的 KVC 兼容属性是非常乏味的,要定义一个属性,需要以下代码
//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];
}
定义一个属性需要 20 多行,我经常在一个特定的类中有几个属性......当然有更简单的方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过像accessorizer这样的软件吗?
http://itunes.apple.com/it/app/accessorizer/id402866670 ?mt=12
否则我认为一个简单的 bash 脚本可以节省您的时间;)
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 ;)