5 Replies
      Latest reply on Apr 17, 2019 9:29 AM by jsant
      kebos Level 1 Level 1 (0 points)

        I saw a question similar to this but I wanted to ask it pertaining to my situation.

         

        Basically I have an app that is like an encyclopedia.  The app will contain "articles" about different subjects.  I will be writing all of these articles.  The user will not be capable of writing or editing any of the articles.  The user just types in a search term and sees the articles I have written.

         

        Now the question is, how do I store all of these articles?  Right now I have them all in a giant txt file which I am parsing into arrays of strings every time the user searches.  Is there some obvious or better way to store all of this data?  Thanks.

         

        P.S. One problem I am having is that I use special characters to delimit where one article ends and another begins and also to designate other information about the articles.  It can be a pain because if I make one typo with these delimiting characters, it will crash the app and I will have to search this entire text file to find where the typo was.

        • Re: Another data storage question
          QuinceyMorris Level 8 Level 8 (5,930 points)

          What is the average size of an article? What is the total size of all the articles?

           

          In roughly increasing order of sophistication, your choices include:

           

          1. A giant text file. This is not absolutely a terrible thing.

           

          2. A giant file with some internal structure that either lets you read only parts of it, or that allows to parse it more easily.

           

          3. A folder with one text file per article. You make this into a "package", which means that it looks to a user like a single file, if that's necessary.

           

          4. A database with one text file per record, or something like that.

           

          There's no real correct answer, but a pragmatic approach is to do something different only if you need to solve a problem you know you have, and not one you think you might have.

          1 of 1 people found this helpful
          • Re: Another data storage question
            Claude31 Level 8 Level 8 (5,655 points)

            How many articles do you consider ?

            100 ? 1000 ? More ?

            In any case, I would avoid a single flat text file. You found the problems yourself.

             

            if 100, you could store each individually in the app resources, as separate files.

             

            Beyond that, you should consider a CoreData, which will also let you create indexes, …

             

            Last point : look at Appstore conditions, such an app, if it has not advanced functions, may not be accepted on the store.

              • Re: Another data storage question
                kebos Level 1 Level 1 (0 points)

                The articles are small - mostly 100 words or less, many are less than 20 words.  My plan is that there will be thousands of them.  Maybe 5-10 thousand total once I'm done writing them all.

                 

                My other concern is about how to protect the data from somebody simply copying it all.  Once somebody has the app, is all of this information easy to extract if I use, say CoreData?  I am talking about someone looking at the app file and trying to "steal" the encylopedia so to say.  Which approach would protect well against that?

                  • Re: Another data storage question
                    eskimo Apple Staff Apple Staff (11,085 points)

                    One other question: do the articles change independently of the app?  Or is your app always using the articles baked in to it?

                    The articles are small - mostly 100 words or less, many are less than 20 words.  My plan is that there will be thousands of them.  Maybe 5-10 thousand total once I'm done writing them all.

                    I’d probably use a SQLite file for this.  Critically, the article sizes you’ve described are well within SQLite’s abilities.  You may also be able to take advantage of SQLite’s full text search (FTS) feature.

                    My other concern is about how to protect the data from somebody simply copying it all.

                    I’ve posted about this many times.  The posts most appropriate to your case are in the old DevForums, here and on this thread.  If you have problems accessing these, let me know and I’ll copy them over to the new forums.

                    Share and Enjoy

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