iOS应用程序配置文件 [英] iOS Application Configuration File

查看:115
本文介绍了iOS应用程序配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#应用程序中,我总是使用 app.config 文件来保存我的应用程序的一些数据,以便在需要时加载(例如,连接字符串) )。

In a C# application I always used an app.config file to save some data for my application to load when needed (e.g Connection String).

在iOS应用程序中保存此类信息的最佳方法是什么?

What is the best way to save information like this in an iOS application?

推荐答案

你可以创建一个属性列表文件(在XCode中有一个模板,只有文件 - >新文件并选择那里),所以你会有类似settings.plist的东西,或类似的东西那。您可以将plist视为key => value配置文件,区别在于除了纯文本作为值之外,您还可以保存数组和字典。

You can create a property list file (there is a template for that in XCode, just to to File -> New file and choose there), so you will have something like "settings.plist", or anything like that. You can think of a plist as being a key => value config file, with the difference that you can also hold arrays and dictionaries, besides plain text as value.

使用NSBundle在您的应用中加载文件,例如

Use NSBundle to load the file in your app, like

NSString *path = [[NSBundle mainBundle] pathForResource:@"settings" ofType:@"plist"];
NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:path];

然后,您可以将您的密钥作为常规字典访问。只是不要忘记[释放]之后;)。

You can then access your keys as a regular dictionary. Just don't forget to [release] it after ;).

这篇关于iOS应用程序配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆