美文网首页
iOS CoreData简单的增删改查

iOS CoreData简单的增删改查

作者: f029a4783122 | 来源:发表于2018-08-02 02:22 被阅读1次

    增加数据操作.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];
        }
    

    相关文章

      网友评论

          本文标题:iOS CoreData简单的增删改查

          本文链接:https://www.haomeiwen.com/subject/ktgdvftx.html