Reputation: 3079
In my app there are five targets. Every target has its own plist.
I want to get 2 urls in AppDelegate
when I build a target. Those 2 urls are different for each target. There are 5 plists (MyApp1-Info.plist
, MyApp2-Info.plist
, MyApp3-Info.plist
, MyApp4-Info.plist
, MyApp5-Info.plist
). Each attached with only 1 target.
I have put those urls in plists. If I build MyApp2
then I should get urls from MyApp2-Info.plist
. How can I do that? Or is there any better way to do that?
Thanks in advance.
Upvotes: 1
Views: 357
Reputation: 122391
The better method of using a common source file within multiple targets is to use preprocessor macro that is different for each target. This directs the source file to perform different actions, or use different values, depending on which target is being compiled.
For example assume you set the prepropressor macro TARGET
to 1
, 2
, etc. (or something more meaningful to your project), by setting the flag -DTARGET=1
, -DTARGET=2
, etc in the Xcode build settings, then the source file can use different URLs as simply as:
#if TARGET == 1
#define URL "http://one.com"
#elif TARGET == 2
#define URL "http://two.com"
#else
#error Invalid TARGET value
#endif
and away you go.
You can obviously also provide any amount of conditional-compilation using this method, for example:
#if TARGET == 1
doSomethingDrastic();
#endif
This is a much simpler, and a much more traditional, approach to defining per-target behaviour than embedding stuff within a .plist
file.
Upvotes: 1