1
votes

I want to sync via iCloud in a Core Data app. Besides some string attributes in Core Data I also want to sync images. I did a lot of research and it seems there are two approaches to achieve this. The opinions really vary so I am confused which one is the better solution?

Approach A:

Store images in Core Data as Binary Data.

Pros:

  • Everything is synced with Core Data sync at the same time in one sync solution.

  • No extra code, which is a big plus for me since I am using Ensembles Core Data Sync Framework which is working really good.

Cons:

  • People say you should not sync larger data with Core Data. But what is "Allow External Storage" for ? - I read that checking that option could lead to data loss when migrate the Core Data model. But I thought that s what it is for ? For syncing larger data... !? Should I check this or not ? Opinions vary on that...

Approach B:

Store images local in Document Directory and store the url to it in Core Data.

Pros:

  • Avoid Approach A´s cons.

Cons:

  • Two sync solutions needed working parallel. Core Data sync and UIDocument sync for the images. - Will this work really synchron? Could it be that Core Data is already synced while UIDocument sync has failed or is slower or whatever?

  • Much more code. Very complex, very complicated.

1

1 Answers

1
votes

It seems you are between a rock and a hard place. You researched your problem well and the options you outline are the correct ones (well, one of them is).

What I can guarantee you is that performance will deteriorate quickly if you go for option A and the images accumulate into any significant number (could be as little as several hundred, depending on size). Even loading a single image from the database could already result in noticeable lag if the size is large.

The UIDocument solution is feasible. It is really not so complicated. Users expect that text is synced immediately and images can take a while, so as long as you keep the UI responsive, this is not an issue during syncing. Indeed, you can expect syncing taking longer for the images - it's sort of logical. One more reason to separate this from the other data.

I hope this will help you make a more informed decision. Don't choose your solution based on your present level of expertise. If you can deal with Core Data, you will have no problem setting up UIDocument in sync with it ;-).

Edit
That being said, let me explain "Allows external storage". That means that Core Data can decide if it wants to store this attribute in an external file rather than in the database binary file. So if you decide to go with option A, this could increase performance and keep the database from becoming too large. I believe the iCloud syncing should also work as expected.