0

I have read tutorials and found different methods for saving your data such as pure SQL, Core Data, Archives and NSUserDefaults.

I am thinking about creating an Application that will be kind of an RPG where I will create a class with different variables. This class and it state must be saved an persist through App cancellation, iPhone booting and App updating.

I. Which ones of the previous methods fullfill this?

Also I have a Q about Core Data. If I just want to store a variable, lets say a date for instance, in an entity. Lets say that the property is called dateJustNow and it is an attribute.

II. Do I have to create new rows for each saving of dateJustNow? Or are there other ways to save only ONE state of an variable and fetch it when needed? Maybe I am mixing variables (singles) and attributes (collections)?

Sincerely yours

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Nicke
  • 133
  • 12

2 Answers2

1

The rule is:

  • Use NSUserDefaults to save application state information. This is information about the operation of the app itself e.g. last launch time, preferred font, last open view etc. The user defaults are universally accessible and fast but lightweight. They can store only bits and pieces of data and they don't store any logic.
  • Use Core Data to model, manage and persist the actual data and logic that the app deals with. Core Data manages large, complex data and its associated logic.

In the case of game, you would use NSUserDefaults to save data about the operation of the app e.g. the user can set a preference for which view the app will startup to. However, the actual logic and data that encodes the rules of the game and changes in the game state should go into Core Data.

TechZen
  • 64,370
  • 15
  • 118
  • 145
0

To me, it sounds like you are looking for an OR-mapper. Use SQLite directly to save states. If you were to write a multi-player online RPG, Core Data would have been great for the large amounts of data.

From this answer:

Although Core Data is a descendant of Apple's Enterprise Object Framework, an object-relational mapper (ORM) that was/is tightly tied to a relational backend, Core Data is not an ORM. It is, in fact, an object graph management framework.

Also, here's a very good read: http://inessential.com/2010/02/26/on_switching_away_from_core_data

Community
  • 1
  • 1
Simeon
  • 5,519
  • 3
  • 29
  • 51