增
增加数据操作.png
查
NSFetchRequest *request = [Person fetchRequest];
//对查询结果排序
//NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
//request.sortDescriptors = @[descriptor];
//查询条件
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like %@",@"*ll"];
request.predicate = predicate;
NSArray *arr = [context executeFetchRequest:request error:&error];
for (Person *p in arr) {
NSLog(@"名字:%@,年龄:%d,身份证:%@",p.name,p.age,card.no);
}
改
for (Person *p in arr) {
p.age = 18;
}
//保存
[context save:&error];
删
for (Person *p in arr) {
//删除
[context deleteObject:p];
}
网友评论