Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

356
Vistas
Adding variables at build time in Xcode

I have some dynamic values I need to change based on the type of build I am doing in Xcode.

I have created 2 schemes DEV and PROD and set environment variables in each

enter image description here

I then consume these in code as follows

var serviceDomain: String {
    let envVar = ProcessInfo.processInfo.environment
    guard let value = envVar["APP_SERVICE_DOMAIN"] else { fatalError("Missing APP_SERVICE_DOMAIN enviroment variable") }
    return value
}

Is this the correct way to approach this?

Once an app is compiled, should these values now be bundled with it?

I have an issue in that once I've stopped my simulator, if I try to open an app built this way, it crashes and I suspect the environment variables aren't present anymore.

In short, I would like a build for dev that uses one set of variables and a build for release / production that uses another.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You don't need environment variables at all!

Go to build settings and search for active compilation conditions:

enter image description here

Add DEBUG for Debug and RELEASE for Release as I have done here.

Then declare your variables. Let's say you want a to be 1 in release mode, and 2 in debug mode,

#if RELEASE
let a = 1
#elseif DEBUG
let a = 2
#endif

And that's it!

The compiler will choose one of the values to compile, depending on your scheme's Build Configuration. Here, it is debug, so 2 will be used:

enter image description here

More details on this #if thingy

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda