获取常量值:无法识别的选择器发送到实例错误
使用我的 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[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 获取此错误显示 code BETWEEN {"06", "07"}
NSManagedObject 的模型类,具有属性 code
:
@interface MedicalCode : NSManagedObject
@property (nonatomic, retain) NSString * code;
@property (nonatomic, retain) NSString * codeDescription;
@property (nonatomic, retain) NSString * name;
FRC 方法:(ICD9Procedure 是MedicalCode)
- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil)
{
return __fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ICD9Disease" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate *myPredicate = [NSPredicate predicateWithFormat:@"ANY code BEGINSWITH[c] %@", self.predicateFilter];
[fetchRequest setPredicate:myPredicate];
[fetchRequest setFetchBatchSize:20];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"code" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
[aFetchedResultsController release];
[fetchRequest release];
[sortDescriptor release];
[sortDescriptors release];
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return __fetchedResultsController;
}
编辑:
我需要的只是一个过滤数据的谓词。 我有一个名为 code 的实体的属性,其格式类似于 55.534
。 我正在尝试获取某个范围内的所有数据,例如 50-60。
Getting this error with my fetch's predicate
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 shows code BETWEEN {"06", "07"}
Model Class for NSManagedObject with property code
:
@interface MedicalCode : NSManagedObject
@property (nonatomic, retain) NSString * code;
@property (nonatomic, retain) NSString * codeDescription;
@property (nonatomic, retain) NSString * name;
FRC method: (ICD9Procedure is subclass of MedicalCode)
- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil)
{
return __fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ICD9Disease" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate *myPredicate = [NSPredicate predicateWithFormat:@"ANY code BEGINSWITH[c] %@", self.predicateFilter];
[fetchRequest setPredicate:myPredicate];
[fetchRequest setFetchBatchSize:20];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"code" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
[aFetchedResultsController release];
[fetchRequest release];
[sortDescriptor release];
[sortDescriptors release];
NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return __fetchedResultsController;
}
EDIT:
All I need is a predicate that filters data.
I have a property of an entity called code that is in format like 55.534
.
I'm trying to fetch all data in a range, for example 50-60.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
这对我有用:
所以错误可能出在属性中。
FWIW,
constantValue
是 NSExpression 的一种方法。不确定这是否对你有帮助。我看到你更新了你的代码。现在非常不清楚您的错误发生在哪里,因为您最初发布的代码没有出现在您添加的代码中,也没有提供有关您正在使用的属性的附加信息。
而且您说该错误没有出现在您最初发布的代码中。它发生在您现在发布的另一段代码中,但我不清楚这与原始代码有何关系。
更新
显然,从评论中的讨论来看,事实证明您需要数字,因此请执行以下操作:
最终解决方案
对于那些感兴趣的人:以下显然有效。
Try:
That works for me:
so the error is probably in the properties.
FWIW,
constantValue
is a method of NSExpression. Not sure if that helps you.I see you updated your code. Now it is very unclear where your error happened, since the code you orginally posted does not appear in the code you added, nor does it give additional info about the properties you are using.
And you say the error does not appear in the code you originally posted. It happens in a different piece of code, which you posted now, but it is not clear to me how that relates to the original code.
Update
Apparently, from the discussion inthe comments, it turns out you need numbers, so do something like:
Final solution
For those interested: the following apparently works.