0

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.

  • Determine first whether you want configuration at compile time or configuration at runtime. Significantly different technologies apply depending on the answer to that question. – Hot Licks Nov 12 '14 at 21:25
  • Configured at compile time. Thanks! – Sid Sharma Nov 12 '14 at 22:15
  • Then you don't want runtime plists and the like, and you probably can hope to do a lot with just your pch file and stuff it includes. – Hot Licks Nov 12 '14 at 23:07
  • Also, you should probably investigate "CocoaPods" for separately managing common components. Was it Churchill or Disraeli who said "CocoaPods is a very bad form of common component management, except for all the others." – Hot Licks Nov 12 '14 at 23:09
  • Would I need to create a .h/.m in the project file with the set values, add header to the pch file, and then set prefix-headers in static library to that pch file to get the values and then use the value in the classes that I want? – Sid Sharma Nov 12 '14 at 23:40
  • Something like that. You can set compiler flags in the project config to turn on and off options -- test them in the pch. – Hot Licks Nov 13 '14 at 00:01

3 Answers3

1

You are supposed to pass the proper configuration (whether it will be view frame, color or any other parameters) when you're initializing class instance defined in the static library.

Don't overcomplicate things. You don't need any configuration file for that.

sha
  • 17,824
  • 5
  • 63
  • 98
  • Well that's what I said, but my boss wants it done by a configuration file because he feels it'd be easier for some reason (He comes from a java background). What do I do? – Sid Sharma Nov 12 '14 at 21:01
  • Read any configuration file and pass parameters in the code – sha Nov 12 '14 at 21:06
  • 1
    You tell your boss that this isn't Java and you know what you're doing -- that's why they pay you. :/ – Ian MacDonald Nov 12 '14 at 21:09
  • Can you give me an example please? I've never really worked with config files... Really appreciate it. (I get paid $9 an hour, my doesn't care about my opinion) – Sid Sharma Nov 12 '14 at 21:09
0

Create a plist and read the value on load. This would allow you to externally modify the plist file allowing for easy changes outside of Xcode (if that's his wish).

iPhone read/write .plist file

Community
  • 1
  • 1
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
0

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

The .plist code

emotality
  • 12,795
  • 4
  • 39
  • 60
  • I totally tried to but I need 15 rep. I just started coding a month ago, so I haven't been using StackOverflow very long. Once I build up my rep, I'll be back. :) – Sid Sharma Nov 13 '14 at 01:08
  • Ahh thats cool mate, goodluck! You can always shout for help ;) – emotality Nov 13 '14 at 01:09