M-I-N / NimbleSurvey

0 stars 0 forks source link

[Question] Application environment handling concern #16

Closed minhnimble closed 2 years ago

minhnimble commented 2 years ago

Issue

As per our our API documentation, there are more environments that our API should be able to support, which are Staging and Production, and you only handled the Production environment so far with hard-coded values. I would like to know more on if you have any experiences in handling different environments in a project and if yes, how would you do it in such cases?

https://github.com/M-I-N/NimbleSurvey/blob/c7575c9d61b58f84cd7124cd99f601633de2d22d/NimbleSurvey/API%2BServices/Endpoint%2BNimbleDefaults.swift#L19-L26

M-I-N commented 2 years ago

For managing different environments, I prefer defining separate build configurations and schemes that are glued together in an appropriate manner.

Build configurations: All of the environment have their own DEBUG and RELESE configurations like:

Schemes: Each environment has its own scheme defined. Schemes are configured with the appropriate build configuration files.

After connecting the schemes to their associated build configurations, we need a way to selectively run blocks of code on a particular environment. To do that, we will add custom Swift flags that only apply to the particular build configurations we just created. We add these flags on the Active compilation Condition section of the build settings. Finally in our code, we check for these flags and set appropriate values according to our need.

Optionally we can assign different bundle identifiers to each of the build configurations so we can have multiple copies of app with different environment in our testing devices.


I think the whole process is better visualised through the settings in place than the theory explained above. Please take a look at #18

minhnimble commented 2 years ago

The implementation looks good to me 🚀