Rui Peres
Rui Peres

Reputation: 25917

Schemes or Targets in iOS

I have a project which can differ according to different environments, so the project is exactly the same, only some URL's change. Normally I have my work environment where I access my dummy web services, and then when there is the need to starting using the client's web services, I just want to rapidly switch those URL's. To achieve that, my initial idea was to have different plist files according to each web services end points (the client can have multiple URL's: pre production, testing, production). So:

  1. Is this the best option I have? Have different plist for each web services endpoints? (again the project is exactly the same, only the endpoints are different)

  2. Does it make sense to create a new target for each different environment? Or am I able to do this in the schemes of the same target?

Upvotes: 4

Views: 812

Answers (2)

justin
justin

Reputation: 104698

For simple cases, you can take the following approach:

MONAppsWebServiceURL.h

NSURL * MONAppsWebServiceURL(void);

MONAppsWebServiceURL.m

#import "MONAppsWebServiceURL.h"

#define MON_APP_USE_DUMMY_SERVICE 1

NSURL * MONAppsWebServiceURL(void) {
#if MON_APP_USE_DUMMY_SERVICE
// perhaps you want warnings as errors for distro
#warning using dummy web service
  return the dummy url;
#else
  return the real url;
#endif
}

this requires alteration and recompilation of one file when you do make a change. This approach could also be used to identify the plist to load (as long as you remove it before shipping).

There are more complex solutions for more complex problems, of course, but this is likely all you will need. No schemes or additional targets required in this case, as I see it.

Upvotes: 0

Jack
Jack

Reputation: 133577

According to how many parameters you need to change you could it with a macro, eg.

#define _DEBUG_MODE
  NSString endpoiunt = @"foo";
#elseif
  NSString endpoiunt = @"foo";
#endif

Then you can easily attach a compiler flag for the debug scheme in which you declare the macro without worries on having to different targets.

If your prefer to keep a .plist file you can easily use the same approach but change the file name instead that hardocidng the endpoint. But you'll have both plists copied in the package unless using two targets (I guess it is possible even to conditionally include files in copying phase but not sure how to do it though)

Upvotes: 2

Related Questions