我创建了NSPredicate来搜索我的coredata中的字符串。
所以在这种情况下,有人知道如何在NSString中保存结果[fetchRequest setPredicate:predicate];
。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@",
mytext];
[fetchRequest setPredicate:predicate];
答案 0 :(得分:1)
在@"YOUR_ENTITY_NAME"
确保您的表格包含name
列
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"YOUR_ENTITY_NAME"];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@", mytext]];
NSMutableArray *arrResult = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
NSLog(@"%@", arrResult); //output
答案 1 :(得分:0)
我认为这会对你有帮助
NSArray *fetchedObjects;
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"your entity" inManagedObjectContext: context];
[fetch setEntity:entityDescription];
[fetch setPredicate:[NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@", mytext]];
NSError * error = nil;
fetchedObjects = [context executeFetchRequest:fetch error:&error];
if([fetchedObjects count] == 1)
NSLog(@"%@",[fetchedObjects objectAtIndex:0]);