My application has both offline (SQLite) and online (iCloud) storage. See: Offline First: How Do I Fetch Data?
Now, as stated in my past question above, the application is offline first, and I'm currently following the answer in that question.
How I fetch data: In first run (or rather in every appear of the screen), fetch the online data, and sync it with the local data.
My problem is how to properly generate IDs for both local and online storages.
In the local storage, I do auto-increment (Int) for the index IDs.
Here's what I'm thinking:
When adding a new data, add it to the local storage (in case when internet connection gets off), and then let the (above) event do the syncing thing, see: How I fetch data.
When adding a new data, add it to local, and then fetch the latest ID from the local storage, and increment it by 1 and use it as the iCloudID, like so:
iCloudID = localStorageLastID + 1
When saving a new data to SQLite, I can't get the ID (Autoincrement) of the latest local data. So I do a new query for this.
I think this last idea is the best, but will take few more hours sigh:
Make a new column to the local database for a customId say
(String). And make one too for the online storage. UUID are generated using a
Stringclass on iOS.
Returns a string created from the UUID, such as “E621E1F8-C36C-495A-93FC-0C247A3E6E5F”
Also, if someone could help me with the proper tags for this question, that would be awesome.