0

Im using a strategy where I'm saving images and pdfs as NSData in the respective managed objects where they belong. I'm having a problem syncing with Ensembles that the pdf doesn't always carry over from one device to another. Now I'm not sure if this is due to some flaws in my code or if it's not a good way of syncing chunks of data like this. Does anyone have experience of this?

I'm using Ensembles 2.2 syncing through CloudKit.

Mathias Åberg
  • 99
  • 1
  • 10

2 Answers2

1

Ensembles should handle this fine. I use it for exactly this purpose, syncing image data including PDF.

I would look closer at the handling of the data. Is the value transformer working (if you are using one)? Is the device capable of unpacking and displaying the PDF data?

An alternative to syncing the PDF directly is transforming to a format like PNG before putting it in your store.

Drew McCormack
  • 3,490
  • 1
  • 19
  • 23
  • Yes it seems to come down to my code, the sync works if i 1) Create new object on unit 1. 2) open unit 2 and sync 3) open unit one and store pdf data and sync 4)open unit 2 and sync – Mathias Åberg Apr 23 '15 at 07:01
  • Again I assume the problem I had can be traced to my implementation. I was storing the pdf in a separate managed object, the object was added to another entity through a one to many relationship. When I checked, the object was created but the relationship did not make it through the merge. I worked around the problem by just adding a pdf-property to the entity and scrapped the relationship stuff. – Mathias Åberg Apr 25 '15 at 08:34
  • Hmm, maybe you should contact the ensembles support. It is possible it is a bug. If you are properly setting the relationship, it should come through. It might be an idea if we look at your model and see if there might be an issue in Ensembles. – Drew McCormack Apr 28 '15 at 08:35
  • Ok, I'll e-mail the model and the implementation then. – Mathias Åberg May 03 '15 at 19:51
0

Transformable data type is really just binary under the covers with some additional metadata. Have you tested a simple lightweight migration on an existing store? I suspect the migration would work and would leave the existing data in the store.

If you are looking to get the existing binary data actually moved out of the SQLite file then you are looking at something a bit more involved.

A heavy migration will accomplish what you are looking for but if the stores are large it may take took long and potentially not provide enough feedback for a good user experience. I personally do not use heavy migrations, ever, on IOS but it will accomplish your goal.

An export/import will also work. I generally recommend export/import when a lightweight migration won't work. It involves a medium amount of code but in the end you own the code, understand the entire process and can tweak it to your exact needs.

Rahul Mayani
  • 3,761
  • 4
  • 25
  • 40