问题描述
有人能指点我在Xcode中动态构建核心数据模型的教程吗?
我发现的所有教程都基于静态设计,但苹果文档说可以以编程方式构建模型。在Apple文档集中没有任何示例。
Can anyone point me to a tutorial on building the core data model dynamically in Xcode?All tutorials I found are based on a static design but the apple documentation says it is possible to build the model programatically..sadly no example on that in apple documentation set.
推荐答案
您必须初始化 NSManagedObjectModel
,然后为模型中的每个实体创建 NSEntityDescription
,然后为每个属性创建一个 NSAttributeDescription
。你可以在这篇文章中看到一个基本的例子。
You have to init a NSManagedObjectModel
, then for each entity in your model you create an NSEntityDescription
, then create an NSAttributeDescription
per attribute. You can see a basic example from this post.
这篇关于NSManagedObjectModel - 动态创建模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!