How can I reduce duplication across multiple Xcode targets? - ios

I have an iOS app with multiple targets: Prod, Beta, Alpha. Each target has different icons, a different bundle ID, and different preprocessor macros.
Unfortunately, there's also a lot of duplication across the targets (URL schemes, build settings, etc.). It's a pain to have to make changes to this configuration in every target, and always worry that I missed a target.
Am I doing it wrong?

I was indeed doing it wrong.
I ended up merging targets and creating a Beta configuration, in addition to the existing Debug and Release configurations.

Related

NotificationServiceExtension with multiple targets in iOS Application

I have 3 targets in my iOS application namely Stage, Preprod and Prod. I added NotificationServiceExtension for the Stage target for the development purpose. Since the added NotificationServiceExtension is not available in other targets i.e pre-prod and prod, hence am not able to use the NotificationServiceExtension. Do i have to added 2 more NotificationServiceExtension for Preprod and prod targets? Or there is some different solution?
Thank you.
I'd recommend you to avoid using different targets for different environments. The better way is to use different build configurations, because:
.xcodeproj file will be much smaller
You will need single app extension
You will not need to add each new file to every target
You will not need to recompile the whole app for different environment
So in your case I'd create the following configs:
StageDebug
StageRelease
PreprodDebug
PreprodRelease
ProdDebug
ProdRelease
Here is a nice article about creating build configurations, have a look.

XCODE : Multiple Target

In my project i have added multiple projects for different environments like QA, Stage, Production, UAT. Will it has any impact on app size. Any drawbacks about having multiple targets in my project. Appreciate any help.
It shouldn't affect the app size, since when archiving the app you archive only one target. Unless, of course, the have dependencies between them, which shouldn't be the case if they are for different environments.

Compile different code for same project - Swift framework

I have several apps that using the same core framework, Since each app have some small differences i'm searching for the best way to build the framework with relevant code and parameters.
The best solution (that is not so good) that i found is:
For different code compilation - using targets that include different classes
For different configuration using different Swift flags for each configuration (e.g. debug, release...)
The problems are:
I'm using several targets and each target duplicate the project configuration and i need to maintain all. this approach can lead to some bugs if i change configuration in one target but forget to change it on other target.
For debug/release & stagingA/stagingB/production I'm creating specific configurations instead combining them (This solution is problematic since for each staging i need to duplicate it for release and debug):
release production
debug production
release stagingA
debug stagingA
release stagingB
debug stagingB
Apps struct is:
App A include CoreFramework with code adjustments for A
App B include CoreFramework with code adjustments for B
Each app have debug, release, production... configuration. This configurations affect the framework (these configuration run also on the framework)
==> I'm looking for other/better way to configure my apps project's
Don't make "code adjustments" in the framework based on which client is calling it.
Construct your framework as if it were something provided as a binary release by an external supplier. Any behaviour that may be variable can then only be controlled by run-time configuration through a public API.

Xcode multiple target only add file once

I have a iOS project with multiple targets. Each target has its own plist but builds the same code base to produce slightly different versions of the app.
This works fine but there are some minor issues.
Whenever I add a file (code file/resource), I have to remember to add to all targets.
When I resolve conflicts between branches, it is much more tedious since there are many conflicts in the project.pbxproj file since each codefile/resource is duplicated multiple times.
Is there a way such that I only add to 1 target and make the rest of the targets "inherit" from it. I looked at target dependencies but it doesn't seem to achieve what I want.

Creating Two Applications From One Target

Is there any way to create two iOS applications from one target and project in XCode?
I have searched for it and got no clear answer..
YES, each target is a different app. Just make additional targets, and they will have seperate build settings and plists.
You can use compiler flags to seperate them, similar to the DEBUG flag, using #if and #endif segments.

Resources