Skip to content

apinun-wong/EnvironmentSetUpiOS

Repository files navigation

EnvironmentSetUpiOS

Create Demo by separate Staging, Dev, and Production

I don't understand English well Because the English language
is not my native language. Sorry before you read.

How to add environment in XCode project

Step 1 - Click on the project target and look at Configurations.
Step 2 - Click "+" button in configurations to add new environment (Before they have Debug and Release)
step 1 Step 3 - Choose a duplicate "Debug" configuration.
step2
Step 4 - Add "SWIFT_ACTIVE_COMPILATION_CONDITIONS" This is a name that will use when the App needs to check the environment conditions in Swift programming
Screenshot 2566-07-22 at 00 01 18
For Example
Screenshot 2566-07-22 at 00 01 57


How to add a scheme in iOS project

What do you do?

We need to build with an environment target.
Screenshot 2566-07-22 at 09 18 54

How to add

step 1 - Click New Scheme
Screenshot 2566-07-22 at 09 19 53
Step 2 - Make a new Scheme name (scheme name should likely be environment name.)
Screenshot 2566-07-22 at 09 20 38
Step 3 - Choose Build with new Scheme and Click Edit Scheme.
Screenshot 2566-07-22 at 09 23 10
Step 4 - Click Tab info and choose Build Configuration same scheme.
Screenshot 2566-07-22 at 09 23 56


Add Configurations File when we need to use different settings (App name, version, or something)

Step 1 - Right click in a folder in the project and choose "new file". After searching type with this picture.
Screenshot 2566-07-22 at 09 34 14

Step 2 - Adding new configurations(Focus on "#include" when you used podfile.

#include "Pods/Target Support Files/Pods-EnvironmentSeparateDemo/Pods-EnvironmentSeparateDemo.staging.xcconfig"
#include "Pods/Target Support Files/Pods-EnvironmentSeparateDemoTests/Pods-EnvironmentSeparateDemoTests.staging.xcconfig"
APP_NAME = Demo Staging
VERSION_NAME = 1.0.0

PAGE1_CONFIG_TITLE = Hi Staging.
PAGE1_CONFIG_TITLE2 = I am Developer Staging.
PAGE1_CONFIG_TITLE3 = I live in Thailand Staging.

We use configuration files with plist.info files or build settings in the project.

Screenshot 2566-07-22 at 09 37 26
Screenshot 2566-07-22 at 09 39 26

In Code

    private func setUpUI() {
        let infoDictionary = Bundle.main.infoDictionary
        if let title1 = infoDictionary?["MyKeyLabel1"] as? String {
            self.title1Label.text = title1
        }
        
        if let title2 = infoDictionary?["MyKeyLabel2"] as? String {
            self.title2Label.text = title2
        }
        
        if let title3 = infoDictionary?["MyKeyLabel3"] as? String {
            self.title3Label.text = title3
        }
    }

About

Create Demo by separate Staging, Dev and Production

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published