Build two similar apps from one project - ios

I have a project for a iOS app and wan't to make two different apps from it. I want the apps to have different skins and want the two apps to connect to two different web services. So I want a base app project from which I can select which to build.
I essentially want to fork a project but don't want to maintain two projects
Also they have to be able to be installed on the same device at the same time.
Is there some sort of "good practice advice" on how to do this?
I would also be interested in a similar solution for android projects

A project with different targets will do:
They will allow you to set different Info.plist for each target (which allow you to set different bundle ID, allowing two apps installed at the same device).
It also allows you to set C flags for each target (which allows you to put conditional statements based on the flag in your codes)
You can have the lines that should be executed in the target, in this example the copy target, with ifdef macro:
#ifdef COPY_VER
//lines of code to be executed for the copy target
#else
//lines of code to be executed for the other target(s)
#endif

Related

Keep WatchKit Extension code (git repo) separated from the existing iPhone code (repo)

I wanted to add a WatchKit Extension (with SwiftUI supported on iOS13+) to my existing app (target iOS12) while keeping both codebase separated (two repos).
How can I separate the WatchKit Extension code from the Mobile One?
Will my Watch App with SwiftUI only work for users with WatchOS 6 and iOS13 without affecting the existing users with iOS12?
How about the app binary size increase?
Thanks for reading!
I am not sure if there is a simpler solution, but this one should work:
Separation of both apps:
If you open in Xcode the Source Control navigator, you see that Branches, Tags and Remotes belong to a main entry in the Project navigator, i.e. to a Xcode project. So in order to have separate repos, you need separate Xcode projects to which you can assign separate repos.
You can however have multiple projects in one workspace, so that all files are available in this workspace.
To have one standalone app, and one app with a watch extension, just setup a workspace with your standalone app, and add another new project. This new project needs all files of the original app plus the watch extension.
Since you need files from one project also in the other, you could drag them from one project to the new one, but then they will be copied (a green + badge is shown during dragging). Usually this is not what you want, since you usually don’t want to maintain two copies separately. Instead, you can show such a file in the finder, and then drag it from the finder to the new project. In this case, you have the option only to copy the reference.
Independence of both apps:
Since you have two separate projects, you can set the deployment target in the target’s build settings as required.
Size:
Each project will get separate products, the standalone app only an xxx.app, and the new project xxx.app, Watch.app, and Watch Extension.appex. So there should be no overhead.
EDIT (due to the comment of Ouadie in his question):
I am not sure if I understand your problem:
With the procedure above, you get a single workspace with two separate projects that share part of the files.
The „mobile project“ is the same as you use right now. It has only a single target (despite of test targets) that is built exclusively with the sources required. It has thus the same size as now.
The „watch project“ is new. It has 3 targets, the „mobile“ target, the Watch target, and the Watch Extension target (despite of test targets). It is built with the shared sources, and the additional watch extension sources. Its size is thus larger, but the increase depends of course on your sources.
Since you have 2 repos, the projects are decoupled, but both repos share some files. If you want to decouple them completely, you could copy the files from your current project to your new project (instead of copying only references), but then you had to maintain 2 copies.
I hope this helps!

Hundreds of targets, same code base in xcode configuration

We are at 400+ targets in xcode. It still works fine but there has to be a better way to set this up by keeping the same code base but not having all those targets which could slow down xcode.
Android Studio lets you update the appname, which loads that folder from disk so only that project is loaded to run and program against. In XCode that is not the case, all targets are available.
It's been years but is there a better way now, with hundreds of targets that doesnt involve Git or Branching? The questions in regards to this are old and only for a few projects, we are talking hundreds here.
Your question lacks enough context to make a specific recommendation but in general...
Use Frameworks
If you can, combine sensible things into a single (or multiple) framework target. Frameworks can be more than fancy wrappers around a dynamic library, they can contain helper tools and such as well.
Use Workspaces
If there is a logical grouping to your existing targets you can separate them out into their own Xcode projects. Once you have them in their own projects you can create a workspace that references those individual projects. Even if the combined workspace loads in everything upfront (I don't think it does tho) you can still open and use the separate projects for a fast and fluid experience when working on the components.
Use static libraries
If you have a ton of targets such that one requires A, B, and C, but another needs B, C, D then you can actually put A, B, C, and D together in a static library and rely on the linker to strip out unused code from each individual target. This obviously does not reduce the number of targets you have, but you can make the static library its own project and include it in a common workspace. This will also speed up compilation as the files only need be compiled once.
Parameterize Targets or Use Schemes
If your targets are simply wrapping some external build tool/script with hardcoded parameters (I've actually seen this) you can actually pass a ton of existing variables from xcode to these external tools and eliminate "duplicate" targets. Similarly you can add new schemes if some of your targets are simply permutations of each other. A good example I've seen of this are people that have a separate target for "sanitized" (address sanitizer, etc) builds you can instead create a sanitization scheme instead of a target.
Use "Script" Build Phases
If some of your targets are doing something such as linting then you can instead employ a script build phase to call the linter instead of having a separate target to do it.
Offload Targets to an External build System
Xcode can have targets that simply call out to an external tool/script using the Script build phase (and using variable parameters as mentioned above). This can make sense to do if you already use another build system (make, cmake, etc) for another platform. Use Xcode only for the Mac/iOS specific targets and offload everything else to a cross platform build system.
If the build system outputs errors in a format Xcode understands it will even show file and line errors the same as native Xcode targets. I've seen people write thin wrappers around external tools to catch parse and reprint errors into such a format.

How to use targets to launch multiple apps using the same code base?

I have an iOS project and I want to have several apps in the store with the same code base, but slight changes in assets and some features enabled in an app and other features in another.
I read in some blogs I can do it using some deferent targets...
How Can I Do It?
You can use targets to set user defined properties, set different assets to each target and enable features in a target and disable them on another. I created a blog here with the details of this process. how to use targets to launch multiple

Split localized iOS app into separate apps

I have a dual language localized app that is intended for enterprise distribution and for my purposes, it would be desirable to split it into two separate apps. Some users of the app would need to use both language versions and it would be easier for them to just open a different app than to go into settings and change language each time they want to switch.
What is the easiest way to split such an app into two targets, considering it already has a couple of localized strings files (for text and for InfoPlist) and several language-specific image folders?
Create a new target (one project might have more than 1 target), with a different bundle identifier.
Add a preprocessor macro, e.g. SECONDARY_LANGUAGE=1, into the new target's Build Settings so you'll know which language is being used. You can check for language inside the code with something like
#if (SECONDARY_LANGUAGE)
...
#else
...
#endif

Creating an application with multiple targets in Windows Phone 7

Is there any way to create a project/application which will have multiple targets.Its same as how we create multiple targets for an iPhone application in XCode.Basically I have an app which has to be made for different targets, with almost all the similar functionalities but with little change.
You can use Configuration Manager to add additional configurations to the list of Debug and Release. Then for each configuration go to Project/Properties/Build/Conditional compilation symbols and add a symbol used with your configuration or target, eg. make it SILVERLIGHT;WINDOWS_PHONE;CUSTOMVERSION1
Then in your code you can say
#if CUSTOMVERSION1
Debug.WriteLine("This is a CUSTOMVERSION1");
#else
Debug.WriteLine("This is not CUSTOMVERSION1");
#endif
Otherwise - if you want to make bigger changes - you would create another project and link files from one project to another project - project/Add/Existing Item//Add As Link(an option in the "Add" button menu). You can then add more files or add different versions of these files as needed. You could use Project Linker to do it faster.

Resources