What's the difference between Build Configurations and Targets? - ios

We have five practically identical apps, with a few different icons/names/settings. They are different "brands" of the same app, only differentiated in a few different icons, separate AppGroups, and a few default settings in code. These are created as their own targets in Xcode. It's one codebase, but 5 targets pointing to it.
It started out looking really nice, with five different targets. However, we have now added two extensions to the app. One custom "NotificationContentExtension", and one "TodayExtension"(Widget). Since we have 5 different targets with 5 different entitlements/groups, we found no other way to achieve this than to add these extensions to EACH target. Since an extension is another target, that means we now have 15 different targets.
We're now experiencing extremely slow compile-times, because every time we as much as open the storyboard, Xcode compiles the entire thing once for EVERY (main)target. I don't need to build my storyboard 5 times. Or any of my other files. I have ONE app, but a few different files, and a few runtime-settings.
This made me wonder - each and every one of these 15 targets have two build configurations by default: RELEASE and DEBUG. I noticed it's possible to customise these, and add more. Why not add configurations instead of targets?
E.g instead of "RELEASE" and "DEBUG", make them "MYAPP1", "MYAPP2", "MYAPP3" etc. Each configuration can have their own product name, icons, and whatever, right?
Are there any good reasons not to do this? Is it possible, when dealing with different AppGroups/Entitlements etc.? We have CoreData-databases stored in AppGroups. It is important that these apps can all be installed on the same device without being corrupted by each other.
As far as I can think, this shouldn't be a problem as long as there are a few different FLAG's for each configuration, and customising the code as such.
What about signing?
I read this article/tutorial on the subject, which explained the basics and got me started, but it will be a huge amount of work to actually test it with databases and entitlements and all.

Answering a few years later: The answer was yes btw. Using BuildConfigurations is safe and works perfectly fine. It also removed all the unnecessary build times. We converted the project setup and ended up with three targets (app, widget1, widget2), and multiple BuildConfigurations.
To customize build configs, click on your project in the Project Navigator, then click on the blue "MyApp" (under PROJECT, not under TARGETS), then select "Info" in the top bar. You'll see a list of your configurations. They'll be "DEBUG" and "RELEASE" by default. You can add/remove/customize here. Make it "MyApp1", "MyApp2" and "MyApp3". Then click on your "MyApp" under "Targets", go to "Build Settings", and search for e.g "Product Name". If you hover over it, an arrow will appear next to "Product Name", click it to expand it, then you'll see you can change the value individually for your different configurations, so "MyApp3" can be named "MyApp3" without affecting the others.
This can be done for all Build Settings.
If you have several "flavors", and potentially have to add more later, I recommend NOT changing the individual values directly in "Build Settings", as they're harder to find and easier to forget. You should rather make each relevant value (such as ProductName) inherit from an external key, and create your own .xcconfig-files for each "flavor", which contains all the individual values for these keys. That way, if you need to add another flavor, you can simply add another .xcconfig-file which has all the relevant changes, and you don't have to look through all values in BuildSettings and potentially forget some of them.
When you've done this, to be able to actually build/run each configuration, you'd have to add a scheme to each config.
The only negative side effect I've noticed from this approach is that the app's icon in the scheme-dropdown-list is wrong. They'll all be the same, even if the "App Icon Set Name" is different. The app's icon will be correct when run/installed, but it will display wrong in Xcode's built-in drop-down-list.
Be careful though, you should know what you're doing when changing the build-settings. By default, when you run an app, the DEBUG-config runs, and RELEASE is used for when you "Archive" (when you release). If you don't respect the differences between these two, and just create ONE build config for each of your apps/flavors, you'll either get longer build-times when developing, or poorer performance after release. This is depending on build settings like "Optimization Level" etc. So to be safe you should create "MyApp1DEBUG" and "MyApp1Release" for every app, which are clones of the original "DEBUG" and "RELEASE" respectively.

Related

Different variable value for development and Ad-Hoc/Production in iOS?

In my project there is a variable(Int) value that I want to be different for development and Ad-Hoc/Production because it's hard to test app with large number(100) for that value, so I changed it to 3 to test but now problem is that I have to build app frequently and some time I forgot to change the value back to 100 so is there any way to make this process automated ?
Use different build configurations as described here: http://limlab.io/swift/2016/02/22/xcode-working-with-multiple-environments.html
Targets are usually used for different apps sharing the same code base. For example: Lite and Pro versions of an application or Watch extension etc.
Update:
https://developer.apple.com/library/content/featuredarticles/XcodeConcepts/Concept-Targets.html
A target specifies a product to build and contains the instructions for building the product from a set of files in a project or workspace.
As I already mentioned, targets are usually used for different products which behave different. In your case you duplicate build setting, phases etc. for a single variable you want to be different.
https://developer.apple.com/library/content/featuredarticles/XcodeConcepts/Concept-Build_Settings.html
A build setting is a variable that contains information about how a particular aspect of a product’s build process should be performed.
It is quite enough to manage "different environments" for a single target in order to achieve what you want.

Is there is any way to create a IOS app as build for another app?

I have an IOS app which holds lot of Configuration settings to use the app and also this app is used in 5 warehouses, settings will be differ from one warehouse to another warehouse. So it becomes more painful for the users using this app.. Even ever they install the app then need to set the configuration settings.
So my problem is If i hardcode the settings value, it is very difficult to maintain the code for all the different warehouse. if i do small change in my app have to change in all of the 5 source code.. Even if i decide to maintain 1 code .. i have to change the setting value every time before setting the build.. It is more painful for me.
so my question is..
Is there any way to run a app and set values in configuration settings. And generate this setting app as a build ?? i don't know it will workout or not please share me some ideas..
If I understand correctly, you want to have 1 source code and there is possibility to create different Targets. Each target can have it's own configuration plist file and you can set also different preprocessor macros for each target.
How to use preprocesor macros you can see here: How can I differentiate between multiple targets in xcode at runtime
How to create targets you can see here: Add preprocessor macro to a target in xcode 6
One more possibility (besides targets) is to create a shared library and if you want to apply some configs after installation you can prompt user to download one from a server (for instance)
Yes, you can create different schemas.
For example, you can create an application for Development, Staging, Production.
You can have configurations in plist file and make it variable according to the schemas.
When your application opens it will take the values according to the schema with which it was built.
Follow this guide to create different schemas.
Also, you can integrate Fastlane to generate builds easily with different schemas with simple commands.
Yes you can have one app with different targets and schema. Then just google it there's many articles about.

Best way to Whitelabel an existing iOS App

I started working at a company which developed an App for mobile payment. There is a "Terminal"-App, which receives payments of customers and then there's the "Wallet"-App, which users can download and use to pay (at those terminals).
The project consists out of 2 targets - one for the Wallet and one for the Terminal. The App is used only in 2 Countries. It's all quite sophisticated and has a huge code base.
Now I need to whitelabel the whole product for a client, who wants to use our App (both targets) with his own branding (and maybe some additional features or without some specific features) and I'm not sure what the best way would be to achieve that.
Currently I see 3 options:
Duplicate whole project
To copy the whole project to a new folder and make my changes in that new folder would probably be the most "dirty" approach. At some point, my first code base could differ from the duplicated one too much. Additionally, if any security-related issues would come up, I would have to fix it in both projects.
Create another 2 targets
I was actually thinking that this would be the best way to go. Creating a new target for the Wallet and the Terminal and then checking the current target in the source code to decide which features should be enabled or disabled sounded pretty good to me at the beginning. But then I created the new target and noticed that I will have to set that checkmark on EVERY single class for that new target. Besides that, I'm not sure any more if that's really the best way to go.
Use If-conditions
The third option would be to wrap every function, that will be available in only one of the apps, with an if loop. I see this as the "cheapest" option because it's easy to set up and I can still maintain my code base pretty well.
Is there any other option I have? Which way would yo go?
The most significant difference between the base App and the whitelabeled one will be its language. The whitelabeled version will be right to left, but iOS does a pretty good job on that without needing me to do all the mirroring.
You definitely want the extra targets. Having a new target means it's easy to use a separate bundle identifier, signing settings and more. It might seem like a pain to have to tick a bunch of boxes to add your files to the new target (perhaps quicker to use the target's Build Phase|Compile Sources list in Xcode) but it's worth it to create a real separation between the apps.
Instead of using a bunch of source code checks to determine which white label app you're in, consider making your app more data-driven. A plist file could be used to determine which capabilities your app has, and a different plist file can be used for each target.
For example, it might contain a top-level dictionary called features, with true/false values for a bunch of feature names. You have a FeatureManager that reads the file and is the single source of truth for all app components that want to know if something should be available or not.

XCode Target Duplication via Code

Does anyone know a tried and tested way of duplicating XCode targets programatically?
I've tried this Gist based on the xcodeproj Ruby gem but it doesn't copy all the settings (like it would do if doing it through the XCode UI)
https://gist.github.com/ratazzi/f6d9217654d6605450a0
For anyone reading I've actually taken a different approach with this.
Rather than duplicating targets and changing specific values I've utilised fastlane an in particular the 'set_info_plist' function to change values at build time that are specific to a target.
https://docs.fastlane.tools/actions/#set_info_plist_value
This is useful for things like theming changes as per the build or Free/Paid applications environments where you want one single code base that behaves differently depending on the theme or nature of the application.

iPhone App Building Setup - same code different assets

I have a number of apps (about 16 at the moment and growing) which have pretty much identical code. That is the code that drives them is the same.
There are a few things that change between apps, they are:
A PDF file (inside the bundle)
The icon
The name
4 Storyboard screens
As you can imagine it would be a nightmare to maintain 16 independent projects, my main concerns is that Features/Bug fixes in the main code will have to be applied 16+ times. The other thing is actually building and pushing 16 different binaries to the app store.
At the present time (Jan 2014) I want to know if there is a way to do this easily so that I only have to make a code change in one place and the 16+ other projects are updated and pushed to the store.
I have thought about git, or just having 16 projects and writing a bash script to do it for me but that seems dodgy. What is the most elegant solution to this problem that will reduce my overhead?
p.s. I don't want one app with 16 different icons/pdf due to size reasons
p.s.s. Please don't make as a duplicated, I want to know what solutions are there today, not a link to a slashdot question from 2010 :P
You could create a project for each app (so you won't have to change the project settings, e.g. name, icons, bundle identifier, ...) where you add the different PDF files and setup the storyboard screens.
Then you would create the classes in one project and drag & drop the files to the other project but uncheck the Copy items into destination group's folder option. That way you can change the code in any of the projects and it will be updated in all of them. You still have to build and submit each project on its own.
You can create one Xcode project file, with multiple targets. Each target in the project can have its own plist, icon, PDF and etc. Everything else will be shared and in one place.

Resources