Iphone 使用KVC查找NSSet中的最大值
我试图在此coredata对象中查找order属性的最大值:Iphone 使用KVC查找NSSet中的最大值,iphone,cocoa-touch,nsset,Iphone,Cocoa Touch,Nsset,我试图在此coredata对象中查找order属性的最大值: #import <Foundation/Foundation.h> #import "Story.h" @class Story; @interface Sentence : NSManagedObject { } @property (nonatomic, retain) NSString *text; @property (nonatomic, retain) NSString
#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
我得到以下错误:
[33209:207]*由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[valueForUndefinedKey:]:此类不符合密钥最大值的键值编码”
我很抱歉,如果答案是显而易见的,我没有抓住重点,但我希望能够了解我做错了什么;关于这个主题的苹果文档似乎有点模糊。
谢谢 您误读了文档。您的密钥路径应该是
@“@max.order”
。注意字符串中的@@max是collection操作符
您是对的,文档有印刷错误。无论您在哪里看到
valueForKeyPath“@count”
或类似内容,您都应该在字符串前面添加一个:@
,这会将其转换为valueForKeyPath:@“@count”
如果您误读了文档。您的密钥路径应该是@“@max.order”
。注意字符串中的@@max是collection操作符
您是对的,文档有印刷错误。无论您在哪里看到
valueForKeyPath“@count”
或类似内容,您都应该在字符串之前添加一个:@
,这会将其转换为valueForKeyPath:@“@count”
有趣的是,我从未意识到该文档中的示例是错误的。缺少分号和@
您需要的语法如下:
NSNumber *maxOrder = [sentences valueForKeyPath:@"@max.order"];
有趣的是,我从未意识到那个文档中的例子是错误的。缺少分号和@ 您需要的语法如下:
NSNumber *maxOrder = [sentences valueForKeyPath:@"@max.order"];