1
@interface Keyword : NSManagedObject

@property (nonatomic, retain) NSString * thekeyword;
@property (nonatomic, retain) NSSet *businesses;
@property (nonatomic, retain) NSSet *catalogWithThisKeywords;
@property (nonatomic, retain) NSSet *images;
@property (nonatomic, retain) CategoryNearby *shortCutSearches;
@end

我想得到一个按排序的请求businesses.count

所以我提出这个要求:

(lldb) po request
(NSFetchRequest *) $4 = 0x089ccca0 <NSFetchRequest: 0x89ccca0> (entity: Keyword; predicate: (TRUEPREDICATE); sortDescriptors: ((
    "(businesses.count, ascending, compare:)",
    "(thekeyword, ascending, compare:)"
)); type: NSManagedObjectResultType; returnsObjectsAsFaults: NO; )

注意businesss.count 作为第一个sortDescriptors

这是结果:

2013-01-07 16:19:50.391 BadgerNew[88578:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSDictionaryMapNode 0x89c4720> valueForUndefinedKey:]: this class is not key value coding-compliant for the key count.'
*** First throw call stack:
(0x2208022 0x1d8ecd6 0x2207ee1 0x149eefe 0x140d831 0x140cc99 0x1a22c08 0x143eae2 0x14108c5 0x143f911 0x141087c 0x143e18b 0x1440904 0x1a212e9 0x1a20229 0x1a2004b 0x19a945d 0x19a72fd 0x465bf 0x46372 0x10d443 0x10cedb 0x142f63e 0x14281e7 0x1427eea 0x14b80ad 0x1f65330 0x1f67509 0x213f803 0x213ed84 0x213ec9b 0x292b7d8 0x292b88a 0xaf1626 0x252d 0x2455)

嗯……怎么了?

someKeyword.businesses 的类型是支持的 NSSet count

4

1 回答 1

2

您可以使用“键值编码编程指南”中记录的集合运算符。

在您的情况下,排序描述符

[[NSSortDescriptor alloc] initWithKey:@"businesses.@count" ascending:YES]

应该管用。

于 2013-01-07T10:00:40.817 回答