0

Every ios app contains images, specific colours, custom messages to show in alert, themes etc. I want all these resources in one place.

  1. Can I use nsuserdefaults? and is this a good option?

  2. Should I use plist file and read/write from documents directory?

  3. Or I should I create a class which contain an array or nsdictionary that hold all resources files name?

Or Any other best practice?

S.J
  • 3,063
  • 3
  • 33
  • 66

3 Answers3

1

For the third option, if you are going to actually store the data, you cannot use classes. There is an option of Core Data in iOS. It acts like a database containing much more features. Since its an embedded framework, works really fast and will answer to your most storage needs.

Engnyl
  • 1,380
  • 16
  • 24
1

Depending on your target you can specify the kind of resources you want to use. For images, you could for example images named:

  • alert_image_1_
  • alert_image_2_

And depending on your target, you could get the correct image by appending the name of it. So if you had a target called DemoApp, you could append that name to the image like:

  • alert_image_1_DemoApp
  • alert_image_2_DemoApp

And use that one. For custom messages, usually the .strings file is more than enough, so you can localise your application. For themes, I am not exactly sure what you mean. I am quite sure, based on what you said, that core data, wouldn't be necessary. Finally you can create a bundle, and based on your target, you can use the correct one.

Community
  • 1
  • 1
Rui Peres
  • 25,741
  • 9
  • 87
  • 137
  • Hi jacky, if I want to use different themes for my iOS app and every theme will have different images and colors, what will be the best option from above 3 I mentioned? – S.J Jul 22 '13 at 14:04
  • I would use environment variables that based on your target would use a certain theme with a certain colour. In your case, I would exclude `NSUserDefaults` and `NSDictionaries` for that. A plist would help, where you would use the one you want, based on certain criteria (perhaps environment vars). – Rui Peres Jul 22 '13 at 14:11
  • Thank you for nice reply :) – S.J Jul 22 '13 at 17:38
0

This all depends basically on type of data and its size. It may also depends on the ease of access.

1) NSUserDefaults is used to store some data which might be helpful for the user most of the times.

2) Plist file can be used as local store normally for average sized data.

3) Creating a class for common usage can be good. But if the size of data increases then it will be not good.

Other store can be by coredata and sqllite for large and relational data.

Hope this might help :)

Vish
  • 341
  • 1
  • 4
  • 19