开发者

iPhone: mechanism for adding and reading app-wide data

开发者 https://www.devze.com 2023-01-15 07:59 出处:网络
I\'m looking for a mechanism to add and r开发者_如何学Cead app-wide data, something similar to Web.config under .NET.

I'm looking for a mechanism to add and r开发者_如何学Cead 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.


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号