iOS

Accessing configuration values from code

Accessing configuration values from code

While you can provide some project settings per environment via variable replacement in our Info.plist file, you should also view some of your config variables from code, such as our ROOT_URL and API_KEY. Let's start by putting them in our Info.plist file.

We'll have to add two new items to the plist because Xcode projects don't include a ROOT_URL or API-KEY key by default. To do so, tap anywhere else in the file on the button. Set the Type to String and the value to the value you substituted from our xcconfig files, as follows:

You can use Swift to access these parameters now that they're in our plist. Creating an Environment.swift file is one approach that is recommended. This will include an enum with no cases used as a namespace for accessing the plist and its variables

Top course recommendations for you

    Mongodb Tutorial
    2 hrs
    Beginner
    26.1K+ Learners
    4.53  (2530)
    Android App with Python
    2 hrs
    Beginner
    34.2K+ Learners
    4.41  (955)
    JavaScript Projects
    2 hrs
    Intermediate
    43.7K+ Learners
    4.48  (2113)
    HTML Attributes and Tags
    2 hrs
    Beginner
    53.3K+ Learners
    4.52  (3292)
    HTML Tutorial
    6 hrs
    Intermediate
    70.3K+ Learners
    4.55  (4329)
    CSS Properties
    2 hrs
    Beginner
    26K+ Learners
    4.46  (1398)
    CSS Tutorial
    2 hrs
    Intermediate
    44.9K+ Learners
    4.51  (2893)
    Docker Best Practices
    2 hrs
    Beginner
    7.3K+ Learners
    4.45  (331)
    Docker for Intermediate Level
    3 hrs
    Beginner
    8.2K+ Learners
    4.41  (281)
    Docker Orchestration
    3 hrs
    Intermediate
    4K+ Learners
    4.57  (148)