iphone:[NSNull getCharacters:]:使用NSPredicate无法识别的选择器错误(iphone: [NSNull getCharacters:]: unrecognized selector error using NSPredicate)

IPhone IT屋
问 题

Hi when I try to search an entity in core data on certain fields, I get the following error:

[NSNull getCharacters:]: unrecognized selector sent to instance

This is code I am using to set predicate:

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    NSPredicate *resultPredicate =[NSPredicate predicateWithFormat:@"jobtitle=%@",@"Barber"];
    searchResults = [getContacts filteredArrayUsingPredicate:resultPredicate];
}

However, when I set the predicate to something I know is true on other fields, the search works correctly:

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    NSPredicate *resultPredicate =[NSPredicate predicateWithFormat:@"title=%@",@"Dr"];
    searchResults = [getContacts filteredArrayUsingPredicate:resultPredicate];
}

First version searches on title field/attribute, second on jobtitle field/attribute.

Examining the attributes job and jobtitle in the model, I cannot discern any difference between them.

Can anyone tell me where the NSNull is coming from and what it means? Could there be something I am missing in the properties of the attributes that would account for this?

Thanks in advance for any suggestions.

解决方案

Looks like objects in getContacts array don't have jobtitle property in first method. You can check it by printing the first object NSLog(@"%@", getContacts.firstObject) or print the whole array NSLog(@"%@", getContacts)

本文地址:IT屋 » iphone: [NSNull getCharacters:]: unrecognized selector error using NSPredicate

问 题

当我尝试在某些字段的核心数据中搜索实体时,我遇到以下错误:



  [NSNull getCharacters:]:无法识别的选择器发送到实例


这是我用来设置谓词的代码: p>

   - (void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope 
{
NSPredicate * resultPredicate = [NSPredicate predicateWithFormat:@“jobtitle =%@”,@“Barber”];
searchResults = [getContacts filteredArrayUsingPredicate:resultPredicate];
}


但是,当我将谓词设置为其他字段,搜索工作正常:



   - (void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope 
{
NSPredicate * resultPredicate = [NSPredicate predicateWithFormat:@“title =%@”,@“Dr”];
searchResults = [getContacts filteredArrayUsingPredicate:resultPredicate];
}


第一个版本在title字段/属性上搜索,第二个在jobtitle字段/



检查模型中的属性job和jobtitle,我不能区分它们之间的任何差异。



告诉我NSNull来自哪里,这是什么意思?



提前感谢任何建议。


<看起来像 getContacts 数组中的对象没有 jobtitle 属性在第一个方法。您可以通过打印第一个对象 NSLog(@“%@”,getContacts.firstObject)或打印整个数组 NSLog @“,getContacts)


本文地址:IT屋 » iphone:[NSNull getCharacters:]:使用NSPredicate无法识别的选择器错误