Hello Friends
If you developed an App and you want to create different different settings of app like Local, Dev, Prod environments server url change or multiple app developed with same code with minor changes at that time Multiple Target is use full.
How to create multiple target?
- Select project in navigator and select target
- Then Go To Scheme and select Mange Schemes
- Now Target created.
- Now based on target we set preprocessor in Build Settings -> Other Swift Flags
- > Target -> -D DEV
- > TargetPROD -> -D PROD
- Now add this code and change both target and run
If you developed an App and you want to create different different settings of app like Local, Dev, Prod environments server url change or multiple app developed with same code with minor changes at that time Multiple Target is use full.
How to create multiple target?
- Select project in navigator and select target
- Now selecting target and create duplicate target
- Now rename the target (Target Copy -> TargetPROD)
- Then Double tap to rename Target name (Target copy -> TargetPROD)
- Now Target created.
- Now based on target we set preprocessor in Build Settings -> Other Swift Flags
- > Target -> -D DEV
- > TargetPROD -> -D PROD
- Now add this code and change both target and run
import UIKit
#if DEV
let baseURL = "Dev base url"
#else
let baseURL = "Prod base url"
#endif
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print(baseURL)
}
}
In Target => Print "Dev base url"
In TargetPROD => Print "Prod base url"
You can change also Info.plist, File, bundle settings etc.
You can also watch video
If you have any query then comment.
Thank you.