如何根据某些Relationship.count对核心数据发出请求

时间:2013-01-07 09:25:29

标签: objective-c xcode core-data

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

请注意将business.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的类型是支持count的NSSet。

1 个答案:

答案 0 :(得分:2)

您可以使用“键值编码编程指南”中记录的Collection Operators

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

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

应该有用。