I want to make store my programming variable, for example, the image file collections, also the image size, etc. It can be changed during development, but it will not change on the runtime. So, I am consider using a plist. But using a plist need to read it regularly, it seems very un-convenient. So, I am thinking define all the variable on a class file. What do you think? any ideas on that? thz....
The simplest method is to create an array or dictionary to hold you application information. When the app starts, read the plist into memory. When the app quits, write the collection to a plist.
You probably want to leave images on disk until you need them and just store the file paths in the collection so you can read them as needed.
If you need to store small amounts of information or application preferences information, you would use NSUserDefaults.
For more complex information, you need a data model i.e. a dedicated object to manage the applications data. Depending on the complexity, size and structure of the information, you can (1) serialize the object (2) use Core Data (3) use SQL.
[NSUserDefaults standardUserDefaults] is the approach to take if there is any chance you will need to update values during runtime.
Accessing this is quick enough that you can have a random access key-value store that persists. The added benefit if you are not modifying at run-time is that you can edit the plist directly during development in the simulator.
If the key-values really are fixed, do it with a plist in the app bundle. You can load in memory during start-up, or on-demand by:
NSString *someListingPath = [[NSBundle mainBundle] pathForResource:@"someList" ofType:@"plist"];
self.variableList= [[NSArray alloc] initWithContentsOfFile:someListingPath];
NSDictionary also has an initWithContentsOfFile: method to load data from a plist.
You can use the same technique to load images from the bundle.
You may want to take a look at the Bundle Programming Guide for more tips.