views:

34

answers:

3

Hello friends.

I'm looking for a mechanism to add and read app-wide data, something similar to Web.config under .NET.

I'm thinking of creating an AppConfig.plist, and in there I'll store URLs to web services, etc. so that these values can be read and used throughout the app.

Is this an effective way to achieve what I'm after? Do you guys recommend any better alternatives?

Thanks.

EDIT: Doh! Removed mention of version number because, of course, that's in the Info.plist.

A: 

You already have one of these, the Info.plist which contains things like your app name, and its version number. If you want to provide additional information, then that's certainly up to you, storing things like URLs usually isn't done in a property list however; if they potentially change that much, then storing them in a strings database is probably a lot more sensical.

jer
Oh, silly me. Forget version number, made a stupid mistake there. The URLs to web services are very unlikely to change, but they're referenced all over the app. I thought it was the case you can't extend Info.plist with arbitrary values? Either way, you recommend a strings database? How does one use one? Any resources to help me figure it out?
David Foster
To be honest, I recommend defining the URL constants in some place like the precompiled header. I only mentioned the strings db if you were so adamant to keep the URLs out of your code.
jer
A: 

I either use the prefix file, or i use compiler constants inside a header, and include it where ever i need them.

Jonathan
+1  A: 

The usual approach to this sort of thing is to encode the information you want to use as a dictionary of key-value pairs in your application bundle.

Then, load that dictionary and pass it to -[NSUserDefaults registerDefaults:]. The key-value pairs in the dictionary will act as fallbacks. Then, just use [[NSUserDefaults standardUserDefaults] objectForKey:someKey] to access the values.

Chris Parker