此代码返回0个不正确的对象。但是,在删除谓词时,获取请求将返回所有对象。
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数据(阿拉伯语)。
感谢任何帮助。
答案 0 :(得分:7)
尝试:
NSPredicate * pr = [NSPredicate predicateWithFormat:@"FullName beginswith %@", searchText];