Dauris Little

  • About
  • Dauris’s Portfolio
  • Blogging Lyf
  • Contact

Working w/Environments in Swift

Avatar photo
Dauris
Wednesday, 15 August 2018 / Published in blog, iOS, Programming Languages, Swift

Working w/Environments in Swift

According to Wikipedia, an Environment Variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs. Basically, many developers create 3 environments

  • Dev
  • Preprod
  • Prod

Sometimes we need to separate the base URL and do the initial work which should be done for the following state or condition only.

Create enum for environments

if you need a refresher on enum check out the following article

enum Environment { 
   case dev 
   case preprod 
   case prod 
}

Environment Variable

let currentEnvironment = Environment.dev

Execute using a switch statement

switch currentEnvironment {
   case .dev:
       print("execute only if the environment is development")
   case .preprod:
       print("execute only if the environment is preprod")
   case .prod:
       print("execute only if the environment is prod")
   default:
   break
}

Execute code now

First, we initialize the currentEnvironment variable and using conditions use it. Now we can change the baseUrl in AppDelegate along with other interesting code.

Tagged under: environments, iOS, programming w/ swift, swift, swift 4

What you can read next

Discovering C# with Console
Java vs Kotlin
Java Or Kotlin Language: Deciding Which Option to Use for Android Development
Oh, I need A Splash Screen, Right?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

Recent Posts

  • Gesture Controls for Android w/Kotlin

    Incorporating Gesture controls in your android ...
  • Android Rating: In-App Review API

    An app rating and reviews are crucial if you wa...
  • QR Reader in Android w/ Kotlin

    Turn your phone's camera into a QR scanner...
  • Creating Advance Custom Snackbar w/ Kotlin

    Ask 100 different developers about what they fi...
  • Swift Has Tuple

    Swift provides us with a type called Tuple whic...

© 2017. All rights reserved. Designed by Dauris Little

TOP
This site uses tracking cookies to personalize content and ads. AcceptLearn More