开发者

Referencing Entity from external data model - Core Data

I have a external library which includes a core d开发者_开发问答ata model, I would like to add a new entity to this model which has a relationship with one of the entities from the library. I know I could modify the original, but is there a way to without needing to pollute the library?

I tried just creating a new model with an entity named the same, but that doesn't work:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't merge models with two different entities named 'Host''


The safest way to do that is to use some unique identifier in the first model as a reference in the second model. You could use the objectID but that can and does change on migration. This issue can be mitigated but it is more code to deal with during migration as opposed to working with a unique.

The safest way, if you do not have a clear unique is to add a guid field to one of the models so that it can be referenced by the other model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜