我有一个如下课程:
@interface GroupStandings : NSObject<EKMappingProtocol>
@property (copy, nonatomic) NSString* groupName;
@property (strong, nonatomic) NSArray* standingList;
@end
和类似的映射:
+(EKObjectMapping *)objectMapping
{
return [EKObjectMapping mappingForClass:self withBlock:^(EKObjectMapping *mapping) {
[mapping mapKeyPath:@"GroupName" toProperty:@"groupName"];
[mapping hasMany:[StandingsTeam class] forKeyPath:@"StandingList" forProperty:@"standingList"];
}];
}
在StandingsTeam类中,我有一个名为points的属性,我想排序&#34; standingList&#34;一旦我从对象映射中获取它。 有没有办法做到这一点?
答案 0 :(得分:1)
覆盖standingList
属性的setter,在赋值期间进行排序:
- (void)setStandingList:(NSArray *)standingList
{
_standingList = [standingList sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
}
注意:有很多方法可以对数组进行排序。