核心数据NSPredicate with SQLITE store

问题描述:

此代码返回0个不正确的对象。但是,删除谓词时,获取请求会返回所有对象。核心数据NSPredicate with SQLITE store

NSError *error = nil; 

NSEntityDescription *entityDescription = [NSEntityDescription            entityForName:@"Person" inManagedObjectContext:[self managedObjectContext]]; 

NSPredicate * pr = [NSPredicate predicateWithFormat:@"%K beginswith '%@' ", 
        @"FullName", searchText]; 

//NSPredicate * pr = [NSPredicate predicateWithFormat:@"PersonID == %@", searchText]; Works fine 


NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; 
[request setEntity:entityDescription]; 
[request setPredicate:pr]; 
NSArray * arr = [[self managedObjectContext] executeFetchRequest:request error:&error]; 

FullName属性包含unicode数据(阿拉伯语)。

任何帮助表示赞赏。

尝试:

NSPredicate * pr = [NSPredicate predicateWithFormat:@"FullName beginswith %@", searchText]; 
+2

+1使用`%@`替换将自动解释值作为一个字符串。不需要围绕它的单引号。如果您需要添加单引号,则不需要'%K'替换。 – 2011-02-09 18:36:30