English 中文(简体)
Fetched Properties v Relationships (Core Data - iPhone)
原标题:

I m a new iPhone developer (of about 4 months or so) who is starting to look at Core Data.

In the "Beginning iPhone 3 Development" book by Dave Mark it mentions that the main difference between fetched properties and relationships is that fetched properties allow lazy loading. However, I have seen other resources and accepted answers on this site which suggest that relationships do allow lazy loading.

For example, if I have a Department object with a to-many relationship with Employee then I would not want a fetch on a given Department to load all the associated employees into memory.

I would be extremely grateful for an authoritative answer on this point, and on the other differences, as it has obvious implications on any design.

Also, I would be extremely grateful if someone could point me towards a reasonable Core Data resource that is a clear and beginner friendly guide (I have been a Java Developer previously but I am new to the iPhone-Way...

最佳回答

Check out faulting in Core Data:

Using faults, if you retrieve a single Employee object from a persistent store its manager, department, and reports relationships are initially represented by faults. Although the fault is an instance of the Department class, it has not yet been realized—none of its persistent instance variables have yet been set.

If you send the Department object a message to get, say, its name, then the fault fires—and in this situation Core Data executes a fetch for you to retrieve all the object s attributes.

问题回答

From the "Core Data Programming Guide", fetched properties represent "weak, one-way relationships". They simply allow you to define the value of a property with a fetch predicate rather than modeling it directly like a relationship.

One major difference is that fetched properties are not live or dynamic like direct relationships. You must explicitly keep fetched properties up-to-date by manually refreshing the object containing the fetched property when changes occur in your object graph that will affect the value of the fetched property.

I would highly recommend Core Data, by Marcus Zarra. I picked it up a few months ago, and while it is assumed you have some Objective-C experience, it s fairly accessible for beginners too.





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签