6 Replies
      Latest reply on Sep 15, 2019 3:46 PM 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 (7,895 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 (12,735 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.

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

                    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.

                    You can’t delete files from within your app’s bundle.  The iOS sandbox won’t allow it and, even if it did, it’d break the seal on your app’s code signature.

                    That requirement suggests two alternatives:

                    • Don’t include these files in your app’s bundle, but instead download them on request.

                    • Adopt on-demand resources.

                    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 plan is to have a small collection of texts that would come with the basic (free) app. (Those are the ones I had originally intended to place in the bundle.) Only an upgraded version of the app (available through a single in-app purchase) would be able to download additional texts. One purchase would be enough to gain access to all of the other texts.

                         

                        I'd also want to make more texts available for download from time to time. Another requirement is that the user have access to all of their texts when offline.

                         

                        Ideally, the user would have the free texts available immediately when they download the basic app, rather than having to go through an extra step to download them. I'm hoping that be can done automatically from the on-demand resources. I'll read through the information at the link you provided and see if I can come up with a solution.

                         

                        Thanks very much for that link. It looks like it will provide a much simpler solution than the one I originally had in mind. But no doubt I'll have further questions about it!