简体   繁体   中英

Best way to store data on iphone

I am creating a Questions and answers app for iphone which allows user to answer the questions displayed.

Currently I am invoking a web service to store the users answers. But I am slightly worried what if the web service goes down. I need to store the users answers locally and then invoke the web service when it is up and running.

How can I store the users answers when the web service is down. Is Sqllite a good option for this?

Please suggest.

Thanks,

Is Sqllite a good option for this?

Yes, SQLite is decidedly a good option. The other choice would be Core Data.

Use CoreData or SQLite on iPhone?

It depends on the complexity of your data model. I've looked into something like this recently and here is what I learnt. The most popular data storage methods in the iPhone are:

  • plist
    • Good for small quantities (hundreds of Ks) of hierarchical data.
    • Bad if relationships or queries are complex (since you have to write the code).
    • Very easy to learn .
    • Supports array, dict, string, data, date, integer, real, boolean elements.
    • You can store it as XML, which is editable and portable, or as binary files, which is faster.
  • Core Data
    • It's a object graph manager with searching and persistent functionality.
    • You need a good few hours of learning .
    • Easy to use once you set it up .
    • Better than a plist because it lets you manage object graphs, grow your object model, write queries, undo/redo, migrations to modified data models, memory management, and handle concurrent access.
    • Better than SQLite because:
      • The performance is similar and the speed of development is faster.
      • Creating objects is faster.
      • When the objects are in memory, executing queries doesn't require a search in the backend (which usually is either memory or SQLite).
  • SQLite
    • A database.
    • Better than Core Data when the operation doesn't require you to bring objects to memory. Example: update, delete, and select 1 (see if something exists).
    • It has full text search if you compile the extension .
    • Hardest to learn. Easier if you use a wrapper: FMDB , egodatabase .

If you can get away with a plist do that. If you see the amount of code you will have to write is too much work, then switch to Core Data. Only if you are an expert and absolutely need the performance use SQLite (unless, of course, you already know SQLite and not Core Data).

It should be, yes. I'd set up a Core Data based app with entities for Questions and Answers and set up relationships between them. Then just use NSFetchedResultsController or whatever you would like to gather and display the data

You have several options:

  1. Sqlite
  2. Core Data
  3. Client-Side storage

If you wish to go the web based route, I'd take a quick look at Safari Client-Side Storage and Offline Applications Programming Guide .

Basically, you store a local copy of the database in memory so incase the web service is down, users can still use the app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM