If you put your setting in your app's Info.plist file, you can access it as follows:
NSString *eventID = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"EventID"];
You can also store your value in a separate property list file (Settings.plist, for example), include it in your app's “Copy Bundle Resources” build phase, and access it like so:
NSString *settingsPath = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:settingsPath];
NSString *eventID = [settings objectForKey:@"EventID"];
One way to make it easier to read your settings would be to provide access via a class:
@interface CNSSettings : NSObject
+ (NSString *)eventID;
@end
@implementation CNSSettings
+ (NSDictionary *)settingsDictionary
{
static NSDictionary *_settingsDictionary = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *settingsPath = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
_settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:settingsPath];
});
return _settingsDictionary;
}
+ (NSString *)eventID
{
return [[self settingsDictionary] objectForKey:@"EventID"];
}
@end
Using the class above, you would just have to do the following:
NSString *eventID = [CNSSettings eventID];