Hello folks, today with this blog we will learn about how we can create multiple targets for the XCode project.
Introduction
Creating multiple targets in an Xcode project is a common practice to manage different versions or configurations of your application within a single project. Xcode allows developers to manage multiple targets within a single project.
By Creating multiple targets, we can create multiple applications with the same code base without needing any extra setup. Multiple targets are particularly useful when developing variations of applications for different purposes and environments.
Steps to Create Multiple Targets
You can add multiple targets for your Xcode application by following the below steps:-
- Click .proj file in Xcode. Right-click on that and create a duplicate copy of the existing target.
- You can also change the name of the new target and new info.plist file generated for that target. Go to the build settings and search for info.plist then enter your .plist file name
- Then again go to the build settings of the original target. Search for preprocessor macros Add your macros MARKETPLACE=0 you can also change according to your need.
- Then go to the build settings of the copied one target. Search for preprocessor macros Add your macros MARKETPLACE=1 you can also change them according to your need.
- Search for other Swift flags in copied target -DMARKETPLACE because Swift doesn’t support macros directly
- You can access the individual targets by the micros as mentioned below.
1 2 3 4 5 6 7 8 9 10 |
enum EnvironmentType { case normal, marketplace } #if MARKETPLACE static let serverUrl = "Your Url" static let environment:EnvironmentType = .marketplace #else static let serverUrl = "Your Url" static let environment:EnvironmentType = .normal #endif |
We can manage the cases of your environment type as needed and can add multiple cases for multiple targets. Since each target has its info.plist file you can manage the App icon, LaunchScreen and bundle identifier separately for every target.
We also need to specify different GoogleService-Info.plist file for every target to avoid conflicts with the Firebase integration, notification or while uploading the application on App Store.
Conclusion
So, In this article, we have learned about how we can Create multiple targets in Xcode.
You can check out more amazing articles with the Mobikul Blogs.