3 Replies
      Latest reply on Aug 17, 2017 3:12 AM by eskimo
      Adalex3 Level 1 Level 1 (0 points)

        I have always wondered how apps store data. For example, Apple's Reminders app can store a list of reminders, each containing a name, a due date, a priority, etc.   I want to implement features like this is my apps. Just for an example, how would you go about creating a copy of Apple's Reminders app, just the actual reminder storage.

        There are a number of ways I can think of to store just one reminder such as structures, dictionaries, etc. But I dont know how people store whole lists of items. Can anyone tell me how to do this? Thanks in advance.

        • Re: Storing data
          karim Level 1 Level 1 (0 points)

          I typically would either:

          • serialize the data as JSON or a PLIST or other structured file format and save into the application data directory
          • create a SQLlite database on first app startup in the data directory, and use that for persistence
          • use CoreData (not a novice technology)
            • Re: Storing data
              Claude31 Level 7 Level 7 (4,475 points)

              The simplest is to save in NSUserDefaults

               

              When you have changed a value:

                          let defaults = NSUserDefaults.standardUserDefaults()
                          defaults.setObject(valueToSave, forKey: keyForTheValue)
                          defaults.synchronize()
              
                • Re: Storing data
                  eskimo Apple Staff Apple Staff (9,835 points)

                  The simplest is to save in NSUserDefaults

                  I recommend against that.  First of all, Swift programmers should use the Swift-native UserDefaults rather than NSUserDefaults.  Beyond that, however, the user defaults mechanism was designed for storing preferences, not the main data of your app.  Before using user defaults to store some data you should ask yourself “How would the user react if this data was lost?”  If the reaction is “sigh I have to go and change a preference”, go ahead and use user defaults.  If the reaction involves pitchforks and flaming torches, do the work to manage this data yourself (karim gave an excellent list of options for this).

                  Share and Enjoy

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