开发者

What's the point of setRetainsRegisteredObjects:?

开发者 https://www.devze.com 2023-01-02 22:06 出处:网络
Why would I want to set that to YES? What difference would that make? Must I开发者_JAVA技巧 worry about this?setRetainsRegisteredObjects: to YES makes your context maintain a strong reference to manag

Why would I want to set that to YES? What difference would that make? Must I开发者_JAVA技巧 worry about this?


setRetainsRegisteredObjects: to YES makes your context maintain a strong reference to managed objects that it would otherwise maintain a weak relationship with. When you perform a fetch request, the objects returned have a weak reference (by default) to the respective managed object context. Only when an object is modified (added, changed, deleted) does the managed object context (MOC) maintain a strong relationship to the object.

Setting setRetainsRegisteredObjects: to YES ensures that strong pointers will be maintained between all fetched objects.

I don't know what @TechZen is talking about - this can be the cause for a sneaky bug if you're not careful. It's a useful method to invoke on the MOC when you find yourself in a situation where this would be useful.


Worry? I don't know, are you interested in wasting time?

You only fiddle with this particular context attribute when you want to do custom memory management within Core Data (which you almost never do.) I had to go look this up just to remember what it was because I haven't used it in years.

The rule of thumb with Core Data is that if you have an attribute with a default value then you use the default value in the vast majority of cases. That's why its the default.

Unless you see a context attribute changed in virtually every example i.e. the store name, then it is not necessary to change it in 90% of the uses. It is certainly not necessary for a novice to try and change it.

Core Data is intended to be relatively simple once you under it abstractly. Using binding, it is possible to use Core Data on the Mac without writing any code at all. Everything just works with the default configuration.

0

精彩评论

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

关注公众号