Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Strategy 1 with some modifications appeared to be a working solutions (with some flaws though).</p> <p>Legend:</p> <ul> <li>1st device - started online without any content in the iCloud</li> <li>2nd device - started later than first and OFFLINE. Then it gets online after some items added</li> </ul> <p>So here's the updated strategy:</p> <ul> <li><p>All my categories have creation <strong>time-stamps</strong></p></li> <li><p>The categories <strong>cannot</strong> be renamed (only added or deleted - this is crucial)</p></li> <li><p>All my items have a string categoryName field which gets its value upon item creation and updated whenever item is moved to a different category - this <strong>redundant</strong> information helps to achieve success;</p></li> </ul> <p>On insertion of new <strong>Categories</strong>:</p> <ul> <li><p>On insert from iCloud, I get pairs of categories with same name if any</p></li> <li><p>Select <strong>newer</strong> duplicate categories (they will most probably have less items than old ones so we will have less dance in iCloud)</p></li> <li><p>Move their items if any to <strong>older</strong> duplicate categories</p></li> <li><p>Delete <strong>newer</strong> duplicate categories</p></li> </ul> <p>On insertion of new <strong>Items</strong> - if the item belongs to <strong>deleted</strong> category:</p> <ul> <li><p>CoreData tries to merge it and <strong>fails</strong> as there's no parent category any more (lots of errors in console). It promisses to insert it later.</p></li> <li><p>After some short time it <strong>does merge</strong> and insert the item into storage but with <strong>NIL</strong> category</p></li> <li><p>Here we pick our item up, find out it's parent category from categoryName and put it to the correct category</p></li> </ul> <p>VOILA! - no duplicates &amp; everybody happy</p> <p>A couple of notes:</p> <ol> <li>I get a dance of items belonging to the 2nd device (those that will come with nil category to the 1st device) on both devices. After a couple of minutes everything is stabilized</li> <li>No items is lost though</li> <li>The dance happens only on the first iCloud sync of the 2nd (or any other subsequent device)</li> <li>If the 2nd device is started <strong>online</strong> for the first time the chance that duplicate categories case appears is about 25% only - tested on 3G connection - so dance should not affect the majority of users</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload