Read, Write, and Consuming Files / URLs

Hello,

I have an asset pack that I'm use to periodically distribute a sqlite database thats being used to an NSPersistentStore.

Because the database is over a few GBs, and the files in an AssetPack are not mutable, I have to stream the database into a temporary file, then replace my NSPersistentStore.

This requires that the user has 3x the storage available of the database, and permanently uses twice to storage needed.

I'd like:

  • To be able to mark a URL/File to be accessible for read/write access
  • To be able to mark a file / URL as consumed when it's no needed. So that it can be cleared from the user storage while still maintaining an active subscription to the asset pack for updates.

Thank you

You mentioned asset pack and NSPersistentStore so I'd assume you bundle a Core Data store as an on-demand resource (ODR), and use NSBundleResourceRequest to manage it.

There's no way to mark an on-demand resource to be accessible for read / write access, because on-demand resources are supposed to be accessed in the same way as resources in the app bundle, which are read-only.

To your second question, you can use endAccessingResources() to inform the system that you have finished accessing the resource. The system may reclaim the storage some time later, if no other resource request uses the same storage. You can create another NSBundleResourceRequest instance to request the resource next time your need it.

Probably worth mentionig, when accessing a Core Data store as an ODR, you might be able to avoid writing the store by introducing another store that connects to the existing store via Fetched Properties. This topic is discussed in the "Working with a Large Default Data Set" section in this technote. (The technote hasn't been updated, but the content is valid.)

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Hello! There isn’t currently a way to make an asset pack writable on disk without copying its files to a different location, as you’ve discovered. If this would be a valuable feature for you, then please file a feedback report with details about your use case and reply to this thread with the feedback ID. Thanks!

I should note that it’s probably worth investigating whether you can get Ziqiao’s fetched-properties workaround working with Background Assets to avoid the need to make the entire downloaded database writable. If that does end up solving your problem, then please let us know!

Read, Write, and Consuming Files / URLs
 
 
Q