iOS Application Configuration File

后端 未结 8 1479
南笙
南笙 2021-01-31 16:13

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).

Wha

8条回答
  •  北海茫月
    2021-01-31 16:53

    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.

    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 ;).

提交回复
热议问题