Iphone 获取constantValue:无法识别的选择器发送到实例错误

Iphone 获取constantValue:无法识别的选择器发送到实例错误,iphone,objective-c,nsstring,nspredicate,fetch,Iphone,Objective C,Nsstring,Nspredicate,Fetch,使用我的获取谓词获取此错误 2011-08-13 13:49:12.405 Codes[16957:10d03] NSlog Array: code BETWEEN {"06", "07"} 2011-08-13 13:49:12.407 Codes[16957:10d03] -[NSCFString constantValue]: unrecognized selector sent to instance 0x7464610 2011-08-13 13:49:12.409 Codes[1

使用我的获取谓词获取此错误

2011-08-13 13:49:12.405 Codes[16957:10d03] NSlog Array: code BETWEEN {"06", "07"} 
2011-08-13 13:49:12.407 Codes[16957:10d03] -[NSCFString constantValue]: unrecognized selector sent to instance 0x7464610 
2011-08-13 13:49:12.409 Codes[16957:10d03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString constantValue]: unrecognized selector sent to instance 0x7464610'

NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"ANY code BETWEEN %@", [NSArray arrayWithObjects:self.predicateFilterStart, self.predicateFilterEnd, nil]];:
NSLog显示{“06”、“07”之间的代码

具有属性
code
的NSManagedObject的模型类:

@interface MedicalCode : NSManagedObject

@property (nonatomic, retain) NSString * code;
@property (nonatomic, retain) NSString * codeDescription;
@property (nonatomic, retain) NSString * name;
FRC方法:(ICD9程序是MedicalCode的子类)

编辑:

我只需要一个过滤数据的谓词。 我有一个名为code的实体的属性,其格式类似于
55.534
。 我正在尝试获取范围内的所有数据,例如50-60。

尝试:

NSString *start = @"06";
NSString *end = @"07";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"ANY code BETWEEN %@",
                      [NSArray arrayWithObjects: start, end, nil]];
NSLog(@"%@", pred);
这对我很有用:

2011-08-13 23:45:52.019 PredicateTest[18493:707] ANY code BETWEEN {"06", "07"}
所以错误可能在属性中

FWIW,
constantValue
是一种N表达式方法。不确定这是否对你有帮助


我看到你更新了你的代码。现在还不清楚您的错误发生在哪里,因为您最初发布的代码没有出现在您添加的代码中,也没有提供有关您正在使用的属性的其他信息

你说错误没有出现在你最初发布的代码中。它发生在另一段代码中,您现在发布了这段代码,但我不清楚它与原始代码的关系

更新 显然,从评论中的讨论来看,你需要数字,所以做一些类似的事情:

NSPredicate *pred = [NSPredicate predicateWithFormat:@"ANY code BETWEEN %@",
                      [NSArray arrayWithObjects: 
                        [NSNumber numberWithDouble: 50.0],
                        [NSNumber numberWithDouble: 60.0],
                        nil]];
最终解决方案 对于那些感兴趣的人:下面的方法显然有效

NSPredicate *pred = [NSPredicate predicateWithFormat:@"ANY code BETWEEN %@",
                      [NSArray arrayWithObjects: 
                        [NSExpression expressionForConstantValue: [NSNumber numberWithDouble: 50.0]],
                        [NSExpression expressionForConstantValue: [NSNumber numberWithDouble: 60.0]],
                        nil]];

正如我所说,请向我们展示更多:您使用的属性的类型和初始化。可能是属性代码不正确。如果您这样做:
NSString*start=@“06”;NSString*end=@“07”。。。arrayWithObjects:开始、结束、无]而不是?(注释掉真实代码并临时添加)。还请显示您的NSLog调用(不仅仅是结果)。换句话说:提供更多的信息,这样人们可以帮助你。嘿,鲁迪,当你要求的时候,我已经在上面发布了更多的代码。我收到了与您发布的代码相同的崩溃。您所指的NSLog是在我刚刚
NSLog@“NSLog Array:%@”,filterPredicate)时出现的。如果(![self.fetchedResultsController performFetch:&error])
,则错误总是发生在
处。如果它们是字符串,请使用
[NSNumber numberWithFloat:[myString floatValue]]
。您不能直接传递字符串,因为NSPredicate将在字符串周围加引号。
NSPredicate *pred = [NSPredicate predicateWithFormat:@"ANY code BETWEEN %@",
                      [NSArray arrayWithObjects: 
                        [NSExpression expressionForConstantValue: [NSNumber numberWithDouble: 50.0]],
                        [NSExpression expressionForConstantValue: [NSNumber numberWithDouble: 60.0]],
                        nil]];