iphone - 以编程方式使用 ios-core 数据创建新表

标签 iphone ios database sqlite core-data

Core Data 可以让我以编程方式创建新表吗?或者如果我需要,我需要直接使用 SQLite。

谢谢

最佳答案

从 CoreData 的角度来看,您实际上并没有创建新表,因为数据库表只是与核心数据模型关联的一种可能的持久性存储类型。

但是,您可以使用 NSEntityDescription 类以编程方式创建新的核心数据实体。在 NSEntityDescription 类文档中,您会发现:

Entity descriptions are editable until they are used by an object graph manager. This
allows you to create or modify them dynamically. However, once a description is used 
(when the managed object model to which it belongs is associated with a persistent store
coordinator), it must not (indeed cannot) be changed. This is enforced at runtime: any
attempt to mutate a model or any of its sub-objects after the model is associated with a 
persistent store coordinator causes an exception to be thrown. If you need to modify a
model that is in use, create a copy, modify the copy, and then discard the objects with
the old model.

我从来没有尝试过在运行时修改一个,所以我不确定当你有一个现有的 SQLite 持久性存储时它到底有多好,如果有的话。但可能值得尝试一下 NSEntityDescription,看看它是否能让您接近您想要做的事情。

关于iphone - 以编程方式使用 ios-core 数据创建新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10890205/

相关文章:

database - 是否有 REST 数据库连接标准?

iphone - 如何编写测试用例?

iphone - 列出 Cocoa 中所有已连接的 iDevices

ios - Timer.scheduledTimer 在 swift 3 中不起作用

ios - 将新的自定义单元格添加到 UITableView 的顶部

mysql - 何时使用 MyISAM 和 InnoDB?

iphone - 后台核心数据加载问题

ios - 架构 i386 : "_sqlite3_open", 的 undefined symbol 引用自:错误

ios - Xcode 崩溃错误

sql - 成绩数据库表