views:

14

answers:

1

I have an xml file that I need to load. This xml file holds data that needs to be accessed by a few classes. I'm wondering what the best approach would be to deal with this.

Basically I need a way to keep the data centralized and allow various classes to access it. Either that or have each class re-parse the xml file for the data it needs (seems inefficient).

How do you guys deal with loading an xml file with data that is used across your application (and not just in one class)?

Thanks.

+1  A: 

You can keep the data in a singleton object. Call the parser once at the start of the app or whatever and have it set the data in the singleton object. All the other classes then access the data in the singleton.

For an example of a singleton object in Objective-C, see Creating a Singleton Instance in the Cocoa Fundamentals Guide.

DyingCactus
Thanks, that's what I ended up going with. Works well so far.
Nebs