0

Tell me please what's the right way to change e.g. an api url by changing the git branch for requests to the right server.

i have two servers (for example):

and two branch:

  • master
  • dev

is there any way to do like this:

let uploadSomethingUrl = url + "/upload/something"

where url is set depending on the checked out branch

  • "dev" is checked out -> https://www.development.com/upload/something

  • "master" is checked out -> https://www.production.com/upload/something

Deitsch
  • 1,610
  • 14
  • 28
  • What URL? the URL of remote? What requests? `fetch/pull/push`? What is "upload"? `git push`? In what way the question is related to iOS and Swift? – phd Nov 26 '20 at 13:06
  • @phd I think it's more like a api base url – Deitsch Nov 26 '20 at 13:32
  • @Deitsch So the question is "In what way it is related to `git`"? – phd Nov 26 '20 at 14:01
  • @phd i guess he wants to use the dev server url in his dev branch and the master should always use the actual api url. The thing is, this is not how it works, hence my answer – Deitsch Nov 26 '20 at 14:08

1 Answers1

1

No, you cannot check which branch you currently checked out and react on it in code.

But what you can do is set configuration for Debug and Release Builds (or any other custom you want). It may take some fiddling around if you haven't done this before, but this is a clean way to achieve your goal. Here is a guide on how to do it

using xcconfig for you xcode project

You can access these setting in your code, read here:

How can I access a user-defined Xcode build setting?

Deitsch
  • 1,610
  • 14
  • 28