我试图在这个 coredata 对象的 order 属性中找到最大值:
#import <Foundation/Foundation.h>
#import "Story.h"
@class Story;
@interface Sentence : NSManagedObject {
}
@property (nonatomic, retain) NSString *text;
@property (nonatomic, retain) NSString *image;
@property (nonatomic, retain) NSString *thumb;
@property (nonatomic, retain) NSNumber *order;
@property (nonatomic, retain) Story *belongsTo;
@end
使用 KVC。我一直在使用Apple 文档作为资源(示例代码中似乎有错误 - 缺少 : 并且 @ 在错误的位置,但也许我遗漏了什么?)
我尝试使用的最新代码如下所示:
NSSet *sentences = [story sentences]; //this is a valid NSSet filled with 1 or n Sentence objects
NSNumber *maxOrder = [sentences valueForKeyPath:@"max.order"];
NSLog(@"maxOrder:", maxOrder);
我收到以下错误:
[33209:207] *由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[<_PFCachedNumber 0xc4a9004> valueForUndefinedKey:]:此类不符合键最大值的键值编码。”
如果答案很明显并且我错过了重点,我很抱歉,但我希望能深入了解我做错了什么;有关此主题的 Apple 文档似乎有些含糊。谢谢!