NSManagedObjectContext *context = self.myAppDelegate.managedObjectContext;
// 限定查询结果的数量
//setFetchLimit
// 查询的偏移量
//setFetchOffset
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
//
// [fetchRequest setFetchLimit:pageSize];
// [fetchRequest setFetchOffset:currentPage];
//
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Lists" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSPredicate * qcmd ;
if (![str isEqualToString:@""]) {
NSString *attributeName = @"listName";
NSString *attributeValue = [NSString stringWithFormat:@"*%@*",str];
qcmd = [NSPredicate predicateWithFormat:@"%K like %@",attributeName,attributeValue];
}
[fetchRequest setPredicate:qcmd];
NSError *error;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
NSMutableArray *resultArray = [NSMutableArray array];
for (Lists *list in fetchedObjects) {
ListsModel *listModel = [[ListsModel alloc]init];
listModel.listName = list.listName;
listModel.isFinished = list.isFinished;
listModel.endTime = list.endTime;
[resultArray addObject:listModel];
}
return resultArray;
coredata模糊查询
最新推荐文章于 2020-08-23 22:07:24 发布