I need to be able to intialise arrays in my source code with some pre-defined values, that look a bit like below. However each array is going to have possibly thousands of values.
@"key",@"value",
@"key",@"value",
@"key",@"value",
@"key",@"value",
...etc...
How do I initialse (for example) an NSDictionary with these values without having to have thousands of values inline with my source code, ie something like this:
tokens = [[NSDictionary alloc] initWithObjectsAndKeys:
#import "keyvaluepairs1.h"
#import "keyvaluepairs2.h"
, nil];
or even just a pure array like this:
char[] tokens = {
#import "schoolnames.h"
#import "universitynames.h"
}
What I am looking for is not an objective-c “trick”, but more of an understanding on how you can instruct the compiler import or suck in contents of other files. I am open to other ideas on how to achieve this if required.
After much searching, I believe I have found a simple way to achieve this without having to make sure there are text files lying around everywhere. You can make your header files look like this:
And then import or use them like this:
Given that the data will never change, I can’t see any major problems with this.