zoukankan      html  css  js  c++  java
  • iOS进阶(coreData)

    1.CoreData核心对象

    实体管理类 NSManageredObject 实体描述类NSEntityDescription 数据管理类NSManageredObjectContext 数据连接器类NSPersistentStoreCoorDinator 数据模型器类NSManageredObjectmodel

    2.利用CoreData对数据进行增删改查等操作

    注意在创建工程时要勾选coreData

    增删改都是建立在查询基础上的

    创建查询请求

    NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Student"];//查询到的是数据库中的所有内容

    NSFetchRequest *request = [[NSFetchRequest alloc] init];//可以添加谓词和排序

    创建实体

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Student" inManagedObjectContext:self.managedObjectContext];

    request.entity = entity;//给请求添加实体

    创建谓词

     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name = %@",@""];
        request.predicate = predicate;
        NSArray *array = [self.managedObjectContext executeFetchRequest:request error:nil];
        Student *stu = [array objectAtIndex:0];
        NSLog(@"name is %@, gender is %@, age is %@",stu.name, stu.gender, stu.age);

    添加排序

    NSSortDescriptor *des = [[NSSortDescriptor alloc] initWithKey:@"gender" ascending:YES];
        request.sortDescriptors = @[des];
  • 相关阅读:
    session笔记-韩顺平
    带宽
    cookie-韩顺平
    分层模式开发+MVC模式开发--韩顺平雇员数据库管理
    韩顺平-雇员管理系统-学习小结
    常用的PHP数据库操作方法(MYSQL版)
    使用Three.js 基本组件以及流程
    three.js 相机
    多线程的操作与数据绑定
    矩阵-
  • 原文地址:https://www.cnblogs.com/w150385/p/5251744.html
Copyright © 2011-2022 走看看