核心数据中的单向关系
每家餐厅都必须有纬度和经度。但是,每个 LatitudeLongitude 对象都不能有“一家餐厅”,
因此我有一种单向关系并生成编译器警告。
有什么问题吗?
我应该使用 fetchRelationship 吗?但是 fetchRelationship 是什么?
为什么是一种方式呢?为什么它有谓词?为什么叫取呢?我阅读了文档,但似乎不明白它到底是什么。
Every restaurant must have Latitude and Longitude. However, every LatitudeLongitude object must not have "a restaurant"
So I have a one way relationship and generate a compiler warning.
What's the catch?
Should I use fetchRelationship instead? But what is fetchRelationship?
Why is it one way? Why does it have predicate? Why it is called fetch? I read the documentation and doesn't seem to get what it really is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用获取的属性(它们是满足指定获取谓词的托管对象的集合)来表示单向关系。更多信息请参见此处。
更新
您可能应该在您的情况下使用属性,否则您将向
Restaurant
实体添加获取的属性,将其目标实体设置为LatitudeLongitude
并将纬度和经度键值对存储在其userInfo
字典中。它的获取谓词如下所示:You should use fetched properties (which are an collection of managed objects satisfying a specified fetch predicate) to represent one-way relationships. More information here.
Update
You should probably use attributes in your case, otherwise you would add a fetched property to the
Restaurant
entity, set it's destination entity toLatitudeLongitude
and store lattitude and longitude key-value pairs in itsuserInfo
dictionary. Its fetch predicate would look like this:好吧,这是一个非常老的问题,但这就是我现在解决它的方法。
并非所有关系都必须被填补。保持反向(双向)关系,但不一定必须将它们链接起来。
调用
completion
时,localLatLng1
和localLatLng2
均已存在,其中一个链接到餐厅,另一个则不链接。当然,这个方法在这种形式下没有任何意义,它只是为了证明你可以创建对象而不必满足它们的关系。
Z。
OK, super-old question, but here's how I'd be solving it now.
Not all relationships have to be filled. Keep your inverse (two-way) relationships but you don't necessarily have to link them.
By the time
completion
is called, bothlocalLatLng1
andlocalLatLng2
exist, one is linked to a restaurant, one isn't.Of course this method makes no sense in this form, it's just to prove the point that you can create objects without having to satisfy their relationships.
Z.