【发布时间】:2014-04-28 20:22:05
【问题描述】:
我正在尝试对一组 UserWrapper 对象进行排序。包装器对象包含对象 User,而 User 对象包含属性 UserName(我想要排序)。
对一组用户 (source) 进行排序很容易,但是添加的 UserWrapper 层对我来说使事情变得复杂。请帮忙!
这是我的代码,适用于简单的用户数组:
NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"UserName"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)] ;
NSArray *descriptors = [NSArray arrayWithObject:nameDescriptor];
NSMutableArray *contactsStartingWithKey = [nameIndexesDictionary objectForKey:aKey];
[contactsStartingWithKey sortUsingDescriptors:descriptors]; // Exception thrown here because UserName is not a property of UserWrapper, but of UserWrapper.User
【问题讨论】:
标签: ios objective-c arrays sorting nssortdescriptor