4 Replies
      Latest reply on Sep 13, 2019 7:54 AM by Albinus
      Albinus Level 1 Level 1 (0 points)

        My iOS app displays text content loaded from data files. Some of these data files will be bundled with the app. Others will be downloaded from my server. They are all JSON files, and have the same structure.

         

        I want all of these data files to be placed in the same directory. So far, I've just been dragging the bundled files into an Xcode group folder. How would I create a special directory for them? i.e. one that would be part of the directory structure of the app itself?

         

        What I'd like to do is have a directory called Data where both bundled and downloaded data files would reside.

        • Re: Placing resource files in iOS app
          Claude31 Level 8 Level 8 (6,485 points)

          Where is the problem ?

          - creating the directory in the app ?

          - do you want to create it programmatically or in XCode ?

          - transferring files there (in code or in XCode ?)

          • Re: Placing resource files in iOS app
            eskimo Apple Staff Apple Staff (11,795 points)

            What I'd like to do is have a directory called Data where both bundled and downloaded data files would reside.

            That’s not really feasible.  There’s two options:

            • Put the Data directory in your bundle (A)

            • Put the Data directory in your Documents directory (B)

            If you do A, you can’t add downloaded files because your bundle is read-only.  If you do B, the Data directory starts out empty, so you’d have to copy the files from your bundle to the directory.  This works, but it’s a bad idea for a bunch of reasons,

            • It makes updating your app tricky:

              • If you don’t do anything special, the Data directory is left with the data from the old version of your app.

              • If you decide to update it, that’s a whole bunch of extra code.

            • You run the risk of bumping up against the iOS Data Storage Guidelines.

            The approach I recommend is to maintain two directories, one in your app bundle for built-in data and another in the Documents directory (or Caches, or wherever).  Then merge these directories when you present it to the user.

            Even that isn’t trivial though.  If the user deletes one of your built-in items, you need to leave a tombstone.

            Share and Enjoy

            Quinn “The Eskimo!”
            Apple Developer Relations, Developer Technical Support, Core OS/Hardware
            let myEmail = "eskimo" + "1" + "@apple.com"

              • Re: Placing resource files in iOS app
                Albinus Level 1 Level 1 (0 points)

                My main concern is that the app be able to find both kinds of file. If I understand correctly how File Manager works (a big "if"), it should be able to locate them even if they're in different directories. So should I just leave the bundled ones alone, and put the downloaded ones into Resources?

                 

                I should add that I want the user to be able to delete the files if they wish. Some of them are huge, and they may want to save space on their device.