关于coredata 网上的相关资料比较少,大部分是基本用法。于是便找到苹果官方文档进行深入学习。

  分享一下心得,如果用了coredata 必须懂得 coredata Migration,否则app版本更新 core data model schema 变化很大可能导致持久化coredata 出错,程序崩溃。

  以下几种情况 可以简单的用  Lightweight Migration 迁移数据到新版本Model, 如下。

  NSDictionary *options = [NSDictionarydictionaryWithObjectsAndKeys:[NSNumbernumberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,     [NSNumbernumberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

    _persistentStoreCoordinator = [[NSPersistentStoreCoordinatoralloc] initWithManagedObjectModel:[selfmanagedObjectModel]];

if (![_persistentStoreCoordinatoraddPersistentStoreWithType:NSSQLiteStoreTypeconfiguration:nilURL:storeURL options:options error:&error])

  //其他代码

--------------几种情况概括如下--------------------

    1,Simple addition of a new attribute.(为某个Entity 添加属性)

    2,Removal of an attribute.(为某个Entity 删除属性)

    3,A non-optional attribute becoming optional.

    4,An optional attribute becoming non-optional, and defining a default value.

    5,Renaming an entity or property.

  • Adding relationships and changing the type of relationship

    • You can add a new relationship or delete an existing relationship.

    • Renaming a relationship (by using a renaming identifier, just like an attribute)

    • Changing a relationship from a to-one to a to-many, or a non-ordered to-many to ordered (and visa-versa)

  • Changing the entity hierarchy

    • You can add, remove, rename entities

    • You can create a new parent or child entity and move properties up and down the entity hierarchy

    • You can move entities out of a hierarchy。

  

  <注意>You cannot, however, merge entity hierarchies; if two existing entities do not share a common parent in the source, they cannot share a common parent in the destination。这种情况不能用轻量迁移。

官方文档:

https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmLightweightMigration.html#//apple_ref/doc/uid/TP40004399-CH4-SW1

   下篇 《 core data model mapping 》

  

coredata Lightweight Migration 心得相关推荐

  1. CoreData的数据迁移

    CoreData的数据迁移   很多人说CoreData坑多,现在才感觉到,今天上午写代码的时候,发现了一个大问题. 过程如下,之前我自己给coredata的实体添加了几个字段,后来网上的一个用户说我 ...

  2. Core Data 迁移与版本管理

    原文  http://chun.tips/blog/2014/11/28/core-data-ban-ben-qian-yi-jing-yan-zong-jie/ 主题 Core Data iOS开发 ...

  3. 【iOS 开发】iOS 开发 简介 (IOS项目文件 | MVC 模式 | 事件响应机制 | Storyboard 控制界面 | 代码控制界面 | Retina 屏幕图片适配)

    一. iOS 项目简介 1. iOS 文件简介 创建一个 HelloWorld 项目, 在这个 IOS 项目中有四个目录 : 如下图; -- HelloWorldTests 目录 : 单元测试相关的类 ...

  4. SharePoint 2019 Announced: 最新信息

    SharePoint 2019 Announced: 最新消息 My mind is still blown. As you might know, I have been doing some li ...

  5. delegate、传值、跳转页面

    1.打开xcode,然后选择ios--Application--Empty Application一个空项目. 项目目录: 2.输入项目名称以及选择保存路径即可. 3.创建文件夹Model.Contr ...

  6. ios学习-delegate、传值、跳转页面

    ios学习-delegate.传值.跳转页面   1.打开xcode,然后选择ios--Application--Empty Application一个空项目. 项目目录: 2.输入项目名称以及选择保 ...

  7. 多线程编程的一点小心得(1)

    最近有了很多想法,想把我用过的东西都吃透,这样才不会变成所谓的"样样通样样松".我是新手,老鸟请飘过,当然,这篇小心得如果有什么毛病,还请指出来.先行谢过! 其实我本来想把博客当作 ...

  8. 2018年1月iOS招人心得(附面试题)- 答案整理

    2018年1月iOS招人心得(附面试题)- 答案整理 基础不牢,地动山摇. 面试问的大多都是开发所必备的基础知识,通过面试题整理自己的技术栈是一个非常不错的途径. 这套面试题可作为开发同仁的一份复习提 ...

  9. 2020-01-15 Oracle JDK Migration Guide

    本指南的目的是帮助您确定潜在的问题,并就如何将现有的Java应用程序迁移到JDK 13发行版提供建议. 该指南还重点介绍了对JDK 13版本所做的重大更改和增强.原文地址 This guide con ...

最新文章

  1. 不起眼的夫妻店,为何会被阿里、京东、苏宁同时盯上?
  2. MVC中的统一验证机制~续
  3. Excel基础操作(二)
  4. 走的走的居然飞起来了……
  5. golang——strconv包常用函数
  6. ElasticSearch中的分析器是什么?
  7. 关于排版与交互的问题
  8. 免费开源!仿微信仿陌陌类APP源代码整项目开源,包括ADT项..
  9. 七牛云主机全线升级,「两大资源池」实现多云容灾
  10. Android 极光各厂商配置
  11. 输出教学日历表c语言程序,C语言程序设计教学日历2011版.doc
  12. 成功解决 遇到3dmax模型文件出错,找回并修复出错文件
  13. 【0226】信息安全与密码技术
  14. 调用Yahoo API监控外汇汇率
  15. Mac系统安装/升级 Git
  16. 环保数采仪助力绿水青山建设
  17. LinkedIn高级分析师王益:大数据时代的理想主义和现实主义(图灵访谈)
  18. QQ加群组件-iPhone、Android、网页上加入QQ群
  19. 64位 RT-Thread 移植到 Cortex-A53 系统 bug 修复笔记
  20. Intellij idea Tips 之 创建文件自动生成文档描述

热门文章

  1. 第5章 图像分类的数据集
  2. Ubuntu Server 12.04下cobbler + dnsmasq +tftpd-hpa的安装配置(四)
  3. 数组、字符串对象、Math对象
  4. rsyslog的配置文件使用方法
  5. 用命令行工具创建 NuGet 程序包
  6. [转]优秀编程的“艺术”
  7. TypeKit ,use online fonts
  8. Yii-yiic使用
  9. 一万年太久,只争朝夕
  10. (转)mxArray数据类型