开发者

Is there a Notification when CoreData finished reading data from disk?

开发者 https://www.devze.com 2023-04-11 08:16 出处:网络
I have a Mac (not document) app, that uses CoreData. When launching the app, it reads the data stored on the filesystem.

I have a Mac (not document) app, that uses CoreData.

When launching the app, it reads the data stored on the filesystem.

I have to se开发者_开发知识库tup some things in -(void)applicationDidFinishLaunching based on the information stored using CoreData.

So it would be nice to know when my app read everything from disk.

If I do my setup in -(void)applicationDidFinishLaunching i doesn't work. If I do it a few seconds later it works!

Thx!


If you are using object controllers that automatically prepare their own content, you can observe arrangedObjects to find out when they have fetched their content. This does not guarantee that the actual objects are not faults. In fact, that's one of the main strengths of Core Data: objects are lazily loaded from disk.

If you for some reason want to make sure that most disk activity has taken place in applicationDidFinishLaunching, you can perform a custom fetch that specifically does not return objects as faults. Look up "prefetching" in the Core Data documentation. However, there is no guarantee that Core Data won't fault these objects at a later time due to memory constraints, thereby incurring another disk read when those objects are loaded again.

You can of course also use the NSBinaryStoreType, in which case the entire store is loaded into memory synchronously when it is added to the persistent store coordinator.

0

精彩评论

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

关注公众号