0

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:

  1. 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.

  2. 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.

  3. 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 UUID (String). And make one too for the online storage. UUID are generated using a String class on iOS.

    UUID's description:

    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.

asked Sep 25, 2019 at 18:06
4
  • My problem is how to properly generate IDs for both local and online storages. Use GUIDS. Commented Sep 25, 2019 at 18:13
  • 1
    Basically use UUID / proceed with #3, right? Commented Sep 25, 2019 at 18:17
  • 1
    Of course, that's the only way to handle online and offline IDs equally well. Commented Sep 25, 2019 at 18:43
  • Okay. I got it. Thanks a lot! Perhaps you would consider posting this as an answer. Commented Sep 26, 2019 at 3:33

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.