Sid Sharma Sid Sharma - 1 year ago 132
Objective-C Question

Creating a Configuration File in Xcode?

new to Xcode. I have a static library creating a view, but I want to allow a new project to set the view frame in a configuration file that can change the frame size value in the static library. Some kind of global #define variable.

How do I do this in Xcode? I've looked into pbxuser files, pch, xconfigs, and plists but I'm totally lost as to where exactly I'm supposed to set this up.

Answer Source

Lets say your config.plist file is under you project folder and added to your project :

NSString *configPath = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
NSDictionary *config = [NSDictionary dictionaryWithContentsOfFile:configPath];

float xStartPoint = [[config objectForKey:@"xStartPoint"] floatValue];
float yStartPoint = [[config objectForKey:@"yStartPoint"] floatValue];
float objectWidth = [[config objectForKey:@"objectWidth"] floatValue];
float objectHeight = [[config objectForKey:@"objectHeight"] floatValue];

UIView *exampleView = [[UIView alloc] initWithFrame:CGRectMake(xStartPoint, yStartPoint, objectWidth, objectHeight)];
[self.view addSubview:exampleView];

Example of the Plist file :


The .plist code

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download