是否可以通过编程方式生成核心数据结构? [英] Is it possible to generate a Core Data structure programmatically?
问题描述
我目前正在从事一个项目,该项目可能需要能够从描述每个对象,其属性和关系的JSON提要自动生成Core Data模型和类的能力。这将使我们的公司能够在每个项目开始时从CRM中快速生成一个有效的核心数据数据库。
I am currently working on a project which may require the ability to generate a Core Data model and classes automatically from a JSON feed which describes each object, it's properties and relationships. This would enable our company to quickly generate a working core data database from our CRM at the start of each project.
这是否可能/容易实现?如果是这样,是否有人对我入门有任何提示?
我已经创建了使用Core Data的各种iOS应用,但是我从未开发过需要自动创建Core Data模型的应用。
Is this possible/easy to achieve? If so, does anyone have any tips on where I can get started? I have already created various iOS apps which use Core Data but I have never made one which needs to automatically create a Core Data model.
推荐答案
是的,您可以动态创建Core Data模型。可以在没有存储模型的情况下创建 NSManagedObjectModel
和 NSEntityDescription
/ NSAttributeDescription $ c在传递给
NSPersistentStoreCoordinator
之前,可以定义并添加$ c>实例。 Apple在其核心数据中实用程序教程。
Yes, you can create a Core Data model dynamically. An NSManagedObjectModel
can be created without a stored model, and NSEntityDescription
/NSAttributeDescription
instances can be defined and added to it before being passed to an NSPersistentStoreCoordinator
. Apple has an example of doing this in their Core Data Utility Tutorial.
这篇关于是否可以通过编程方式生成核心数据结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!