Core Data: Inheritance, STI or otherwise?

狂风中的少年 提交于 2020-01-13 18:01:27

问题


I can't seem to find any information in the documentation or via Google on this, but if there is something, a pointer to it would be great.

In my app, I have a Thing as a core data class. I intend to have that Thing contain many Items which has a bunch of fields in it, like order and created_date and so forth. However, there are a variety of Item types, each with their own set of fields. Ideally, I'd like to create several subclasses of Item, so that I can access all the items together in a single array or something.

In Rails, I'd use STI for this. Does Core Data support similar behaviour?

Thanks!


回答1:


You can create an Item abstract entity and then have each of your unique items extend from it. Keep the relationship in the abstract so that your Thing can see all of them.

Be warned, however, that under the hood, all of those children will actually be put into a single wide table so you will need to test for performance considerations.



来源:https://stackoverflow.com/questions/2321003/core-data-inheritance-sti-or-otherwise

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!