Reputation: 3
This is my second week learning swift.
Currently, I am trying to create a quote app that generates random quotes. I am storing the quotes in an array. So far the app works well, however, I don't think it's efficient to store the quotes in the view controller file, especially if I am planning on listing 100+ quotes. I came across a comment somewhere suggesting storing a large array of strings in a database or a plist file. I just want to know if someone could suggest the best way to store quotes in a database or something. Any help would be appreciated.
Upvotes: 0
Views: 2062
Reputation: 1147
You can save the quotes in JSON file or plist file or xml file and read them from the file from view-controller:
JSON: http://onebigfunction.com/ios/2015/07/01/reading-local-files-ios/
Plist: https://newfivefour.com/swift-ios-read-value-plist.html
Another option you can use database such as: SQLite, Realm, or userDefaults:
SQLite: https://www.appcoda.com/sqlite-database-ios-app-tutorial/
Realm: https://code.tutsplus.com/tutorials/getting-started-with-realm-database-for-ios--cms-29018
UserDefaults: http://www.ios-blog.co.uk/tutorials/swift/using-nsuserdefaults-with-swift/
Upvotes: 2
Reputation: 430
Instead of doing it in a plist I would really reccommed using Realm Database.
It's a lot easier to setup than CoreData and provides the same functionality, loads of examples and documentation as well.
Upvotes: 0
Reputation: 4621
If you want to store quotes and nothing more, than database or UserDefaults will not be a good choice.
It will be better if you save quotes in plist file or JSON file.
Upvotes: 1