核心数据:重命名属性,而用户及其当前数据没有问题 [英] Core Data: Rename Attribute without having issues with users and their current data

查看:73
本文介绍了核心数据:重命名属性,而用户及其当前数据没有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在表上重命名并为应用程序的新版本添加属性,如果应用程序已安装,我想保留数据。

I just want to rename and add attribute on my table for a new version of my app and I want to keep the data if the app was already installed.

首先,我只是设置选项:

Firstly I just set the options:

        let options = [NSMigratePersistentStoresAutomaticallyOption:true, NSInferMappingModelAutomaticallyOption:true]
        try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: options)

版本模型,所以如果我重命名属性并在新模型上的表中添加其他属性,则应用程序会保留数据吗?

And I created a new version model, so if I rename the attributes and add another attributes to my table on the new model, do the app gonna keep the data ?

推荐答案

根据Apple的轻量级迁移的核心数据版本和迁移指南部分:

Per Apple's Core Data Versioning and Migration Guide's section on Lightweight Migrations:

如果重命名实体或属性,则可以在其中设置重命名标识符目标模型到源模型中相应属性或实体的名称。您可以使用Xcode数据建模工具的属性检查器(针对实体或属性)在托管对象模型中设置重命名标识符。例如,您可以:
...将汽车的color属性重命名为paintColor

这篇关于核心数据:重命名属性,而用户及其当前数据没有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆