Schemes or goals in iOS

I have a project that may differ depending on different environments, so the project is exactly the same, only some URL changes. I usually have a work environment where I access my dummy web services, and then when you need to start using client web services, I just want to quickly switch these URLs. To do this, my initial idea was to have different plist files according to the endpoints of the web services (a client can have several URLs: pre-production, testing, production). So:

  • Is this the best option? Do you have different plist for each web services endpoint? (again, the project is exactly the same, only different endpoints)

  • Does it make sense to create a new goal for each environment? Or can I do this in circuits of the same purpose?

+4
source share
2 answers

Depending on how many parameters you need to change, you can use a macro, for example.

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

Then you can easily attach the compiler flag to the debugging scheme in which you declare the macro without worrying that it has different purposes.

If you prefer to store the .plist file, you can easily use the same approach, but instead change the file name to hardcidng the endpoint. But you will have both sheets copied to the package if two goals are not used (I think it’s possible to conditionally include files in the copy phase, but I'm not sure how to do it, though)

+2
source

For simple cases, you can use 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 changing and recompiling a single file when you make changes. This approach can also be used to identify the plist to download (if you delete it before sending).

Of course, there are more complex solutions for more complex problems, but this is most likely all you need. No schemes or additional goals are required in this case, as I see.

0
source

Source: https://habr.com/ru/post/1412185/


All Articles