从CoreData模型生成类 [英] Generate classes from CoreData model

查看:156
本文介绍了从CoreData模型生成类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一对C#应用程序,一个iOS,一个Mac,使用相同的CoreData数据库。有效地,桌面应用程序填充它,然后作为iOS应用程序的一部分分发。

I'm trying to develop a pair of C# applications, one iOS, one Mac, that use the same CoreData database. Effectively, the desktop app populates it, and then it's distributed as part of the iOS app.

我可以使用XCode生成 .xcdatamodeld 文件描述我想让数据库看起来像什么。我可以使用 momc 将其编译成 .momd 文件。我可以将 .mom 文件包含在我的Mono项目中,并将它加载到 NSManagedObjectModel 我可以访问各种实体的所有属性。

I can use XCode to generate an .xcdatamodeld file describing what I want the database to look like. I can use momc to compile that into a .momd file. I can include the .mom file from within that into my Mono project, and load it into a NSManagedObjectModel, from which I can access all the properties of the various entities.

我还没有搞清楚如何从数据库创建一个类的对象,而不是访问表的属性。任何建议?

What I haven't yet figured out how to do is create an object of a class from the database, rather than accessing the properties of the table. Any suggestions?

澄清:我想要能够在XCode中创建一个表/ c $ c> Person 。我给它两个字段:名称电话。我想能够在Mono中运行类似这样的代码:

To clarify: I want to be able to create a table/class in XCode, call it Person. I give it two fields: Name and Phone. I want to be able to run code similar to this in Mono:

using (var context = new NSManagedObjectContext())
{
  var me = context.Person.GetByID(1);
  me.Name = "Bobson";
  context.Save();
}

显然,从数据库获取它并将其保存的细节将是

Obviously, the specifics of getting it from the database and saving it back will be different, but the gist is there.

推荐答案

根据@ t9mike的评论(如果他做出答案),我放弃使用CoreData来支持更多的跨平台方法。我最终使用Vici CoolStorage作为ORM,虽然我不得不将源代码嵌入我的项目,以使它工作。

As per @t9mike's comment (which I will accept if he ever makes it an answer), I gave up on using CoreData in favor of a more cross-platform approach. I ended up using Vici CoolStorage for the ORM, although I had to embed the source in my project in order to get it working.

这篇关于从CoreData模型生成类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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