Hi Sven Korset. Thank you for this article. I do appreciate that it puts all together a bunch of good practices. However I do want to voice my opinion on having multiple targets for the same product/target as I believe it is a bad practice.
There’s hardly anything worse than having 1000 files in one folder, ok. But it is clearly bad to duplicate a target for different environments.
- Your Xcode project will be terrible to maintain if you have one or more duplicate of your build files in it. Not to say it will be an easy mistake to make to just add your sources to one target, and the day you build the other to realize it just doesn’t compile.
- Your
.pbxprojwill be very long.. it makes Xcode slow in many aspects. - Working in a team and having to solve merge conflicts is easier with a shorter
.pbxproj. And if it’s never really short, you sadly just made it twice longer for no reason.
Configurations are there to help you out with your environments.
- In order to change your bundle id, your asset catalog or just your app icon, you can just use different
Info.plistfiles. In your example it would beInfo-Dev.plistandInfo-Prod.plist.
2. Then, if there is any resources that should not be copied in your production target, you can just copy through a build phase script when configuration != production.
3. Finally, if you have sources you want to exclude in one or another target. You need to decide which target is the default and compiles all sources. Then you set `EXCLUDED_SOURCE_FILE_NAMES` in your build settings only for the configuration that should exclude the sources. I believe this is case is not common so you shouldn’t have too many files to list, but if you did you could just specify a folder/*
Let me know what you think.
There is however one case where you may need to duplicate targets, and that is when you have thesame product for different platforms. Let say MyApp-iOS, MyApp-tvOS and MyApp-macOS or MyApp-watchOS.
