Question

I'm developing an app that uses core data (with UIManagedDocument) for storing user-generated data that I would like to sync with iCloud. I also would like to sync photos that the user takes with the camera within the app.

I read that it's not a good idea to store the actual photos within core data; rather it's better to store the photos in the file system and put the fileURL in core data.

Using this method, what is the recommended approach when using UIDocument to store the photos in the file system (under the Documents folder)? I've thought about:

  1. For each individual photo, use a NSFileWrapper(containing the actual image and thumbnail image), or
  2. Use a top-level NSFileWrapper, and put all NSFileWrappers in it for each photo
  3. Similar to #2, but just put all photos/thumbnails directly in the top-level NSFileWrapper

Which approach is better for syncing photos with iCloud? and are there better approaches?

Was it helpful?

Solution

The best approach in this case is to let Core Data decide where to put it.

Open your Core Data model GUI -- click on your attribute that will hold your binary data -- look to the right -- there is a check box that indicates if Core Data should use external storage if it wants. Select it.

That's all. If Core Data needs to use external storage, it will do so -- you wil neither know nor care what it decides.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top