iOS app with core data, photos & iCloud

青春壹個敷衍的年華 提交于 2019-12-10 17:03:35

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/12437961/ios-app-with-core-data-photos-icloud

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!