0

I'm making a simple memory game to learn more about iPhone programming and I am wondering how I should be storing constant information.

For example:

  • The probability of a certain color being more prominent.

  • The threshold that decides what constitutes a double touch event.

  • ...

Data like this is internal game data that is unlikely to change.

Should I be putting these as constants in the ViewController where they are used? Should I #define them?

rmaddy
  • 307,833
  • 40
  • 508
  • 550
jmasterx
  • 50,457
  • 91
  • 295
  • 535
  • 1
    \If you save values dynamically and retrieving then you can user core data or Plist or sqlite or NSUserDefualt... its all depends on your requirement and size of data. – Tirth Nov 14 '13 at 16:53
  • @iAmbitious No it's not. – Gabriele Petronella Nov 14 '13 at 16:54
  • @GabrielePetronella i edited my comment read it. – Tirth Nov 14 '13 at 16:55
  • @iAmbitious Still no. `#define` is a terrible way. Use a `const` variable instead. – Gabriele Petronella Nov 14 '13 at 16:56
  • There is no good answer for the general question. One can use `#defines`, enums, consts, values loaded from a plist, etc. Each has advantages and disadvantages. One favorite of mine is to define a global dictionary with named tuning/customization values in it. – Hot Licks Nov 14 '13 at 17:10

1 Answers1

2

There's a difference.

If you want to store constants, then use NSUserDefaults.

If you just want them to be there, in your code, just lying there then, #define should be fine.

Sam Fischer
  • 1,440
  • 18
  • 34