这段代码返回了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数据(阿拉伯语)。
任何帮助都将不胜感激。
%@
替换会自动将值解释为字符串,不需要在其周围添加单引号。如果您需要添加单引号,则不需要使用%K
替换。 - Dave DeLong%K
格式说明符是做什么用的?我从未使用过它,并且在苹果字符串编程指南或IEEE PRINTF规范中也找不到任何文档。 - Kevin Sylvestre