0

I'm developing a quiz application. I have 100 questions. For example, what city is the capital of Great Britain?

A. Rome

B. Milan

C. London

D. Oslo

Which is the best solutions to store a data (coredata or sql)?

Voloda2
  • 12,359
  • 18
  • 80
  • 130
  • Possible duplicate: http://stackoverflow.com/questions/523482/core-data-vs-sqlite-3 – 0x8badf00d Dec 25 '11 at 18:49
  • It's sort of a duplicate, however I think it justifies a separate question because this is a specific use-case, where as the link you've provided is much more general. – Jack Lawrence Dec 25 '11 at 18:51

3 Answers3

3

Core Data is a bit more complex to set up than SQL, however in my opinion Core Data is MUCH easier to work with, and keeps you in "objective-c land" where as SQL requires writing tons of SQL statements (as far as I know).

Specific to your use-case, I would think CoreData would be a better fit. You would probably have a Question object with an NSString text property for the actual question and then an NSArray of Answer objects. In CoreData/SQL speak, you would have a table of Questions with a text column. Each Question has a to-many relationship with a table of Answer objects (CoreData handles the dirty work for relationships, but in SQL you'd use primary keys).

As I said in a comment on another answer below, because your database isn't very large and complex initially, you could package a plist or download one from a server to initially populate the CoreData database. Using CoreData instead of a plist means it's much easier to update values on the fly, so you can do things like have a property on each answer object that you can set if the user chooses that answer so you can save state between launches.

Check out Core Data vs SQLite 3 and many other stack overflow answers that talk about the pros and cons of several different methods.

Community
  • 1
  • 1
Jack Lawrence
  • 10,664
  • 1
  • 47
  • 61
1

For a simple question/answer database with only 100 entries I would use a plain text file.

It's simple to create, edit, and read. It's cross-platform should you ever want an Android or other version of your application.

You could use XML, JSON, or a plist (as mentioned above) but why bother? Just alternate lines between questions and answers. Read in the file using [NSString stringWithContentsOfFile] and split up the lines into an array using [myFileContentString componentsSeparatedByString:@"\n"].

NSError *error = nil;
NSArray *testArray = [[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error] componentsSeparatedByString:@"\n"];

It's 1-2 lines of code and no learning curve. The odd entries in the array will be the questions and the even entries will be the answers.

(Reading a plist requires only one line of code, which is nice, but they're harder to edit by hand and aren't simple to read on other platforms should you ever branch out)

EricS
  • 9,650
  • 2
  • 38
  • 34
0

You could also consider just using a .plist file with an array. Your data is not that complex (from what I understand), and plist makes for easy external maintaining/reading and updating via http.

xCoder
  • 725
  • 8
  • 14
  • 1
    Yes, however a plist is annoyingly static (yes... technically you could do it read/write but...) and then the poster wouldn't be able to easily record which answer the user chose for each question. I would recommend, however, that the poster initially populate the CoreData database with a plist the poster could potentially download from a server. – Jack Lawrence Dec 25 '11 at 18:57