How to manage multiple projects in single project copy in iOS? - ios

We have projects which are same for all the cities now I want to make those project in one project, so I can do a change in single project and effected in each.

You need to create one different target for every city, on the same project.
They will have the same core code and then, you can configure different ressources for all of them. (icons, images, fonts ...)
Each of them can use a different plist file in order to have some flags and not others.
To create a new target :
* Go to your project panel (with tabs General - Capabilities - Resources tag ...)
* Open the left panel
* There is a + at the bottom to create your new target (or you can copy an existing one)
You can switch from a target to another on the top bar at the right of the selected device to debug
When you have a file, you can decide on which target he can go on the right panel on the section "Target Membership"
Need screenshots ?

Very nice explained with pictures is here.
You can achieve it by using targets in Xcode.
As well here is explained about targets.

Related

Using a single xcode file for multiple projects

I haven’t tried this before but wanted to know how it happens. Suppose I have an Xcode file for my project called ‘Project A’. Now I want to make another project with the same features as that of ‘Project A’ for a project called ‘project B’. But for ‘project B’, I don’t want to make a different Xcode file but rather want to incorporate the changes in ‘project A’ itself so that when I run the same project, I’ll be able to run project A or project B as per my need. How can I achieve this…?
Click on your project, Goto General > Targets.
Right click on your project Target and select Duplicate.
You will get to choose between iPad and continue to duplicate for iPhone.
Going ahead in each new/existing file, you can choose which target it belongs to and keep doing your development. If you exclude the file from an target, it will not contribute to that app's size.
You can also keep your future files in both Targets depending on your needs.

Different storyboard localization per target

I have a project with 3 targets. Each target needs to suppport only one language, but the language is not the same for each target.
Currently I have
Target 1 (es)
Target 2 (es)
Target 3 (pt)
Most of my strings are in a Localizable.strings file, and I simply target a different file for each target. However, a number of strings are in my storyboards. My problem is that it does not seem possible to create different storyboard localization files for each target. If I change the targeting of the portuguese file, the targeting of the spanish file changes automatically.
A possible solution is to duplicate each Storyboard for each target, but this won't scale well as the number of tagets grow. I could also modify all the text with NSLocalizedString in each ViewController, but this seems tedious and error prone.
Is there a better solution?
Shared Storyboard across targets
While this answer is the preferred approach, you can assign different Storyboard localizations to different targets, while sharing the same Storyboard across all targets.
Prerequisites:
Follow this instructions in this answer.
Concept:
You want to have the Main.storyboard in each target, but a different Main.strings in each target. Additionally, you do not want all localizations to be available in each target.
To achieve this, you must manipulate the .lproj directly, a process which is hidden when merely using the File Inspector.
Step by step:
Create all the pieces by following the steps in this answer.
From any target, remove the Main.storyboard. Of course, select Remove Reference to keep the storyboard around.
In the Finder, locate Base.lproj. Drag and drop Main.storyboard back to your project, and select every target.
In the File Inspector, ensure that the languages are not selected, and that you are still using Localizable Strings.
In the Finder again, locate en.lproj, es.lproj, fr.lproj, etc. Notice that they each contain a version of Main.strings. Drag these .lproj (the entire directories) back into your project. This time, do not select any target
One last time, in File inspector, associate each Main.strings to the desired target. Repeat for each .strings.
Conclusion
By decoupling the .lproj from the .storyboard in the Project Navigator, you can associate files and targets freely.
Demo:
See it at work using a French target, on a device with language set to Français in the Settings:
► Find this solution on GitHub and additional details on Swift Recipes.
Shared localizations across targets
Assuming you already have multiple languages in your project, in the Project Navigator, select your storyboard (say Main.storyboard)
In the File Inspector, under Localization, add English. Pick Localizable Strings which is the default. This will create a Main.string for each language, and share your Storyboard across all languages.
Merely clicking that checkbox in step 2. will add a Main.string (English) for that language, specifically for that Main.Storyboard. Pay special attention to the new hierarchy, these are not Localizable.strings but Main.strings, derived from Main.storyboard:
Localize in each language file to your heart content.
For example, starting with a UILabel which message was in Esperanto, it will appear in English when the device runs in English:
/* Class = "UILabel"; text = "Tiu mesaĝo estas en Esperanto"; ObjectID = "acC-pA-eMt"; */
"acC-pA-eMt.text" = "This message is in English";
Start here to add multiple languages to your project:
In the event you need to add more languages, follow these steps:
In the Project Navigator, select your Project
In the Project and Target List, select, once again, the Project
Select the Info tab
Under Localizations, keep Use Base Internationalization (unless your UI itself must change across languages)
Click +, pick a new language. In the dialog presented to you, select every Storyboard you want to have multiple localizations for.
If you missed Storyboards at Step 5. you can simply add a new language to that a storyboard by following the steps in Assuming you already have multiple languages.
All you need: to make common xcode workspace for your app, then to create a duplicates of main xcodeproj file for your set of languages and make different targets for all of them, also then you can set language for individual project settings in new xcodeproj's. Also you easy can tune build phase 'Copy Bundle Resourses' and others. I use this method. If you have a Xcode's crash during adding project in workspace - open project with Xcode, rename it and rename or duplicate targets (I think same names cause this issue).

Different Builds for the same application

I am developing a product for a client and I have a problem.
The application will be sold to various customers only changing the interface the same (images - images.xcassets).
What is the best way to manage this? I do not want to duplicate the project for each client, but a way to manage builds of each, and the only change will be the bundle id and images.
My project is IOS 6.1>
Thank you.
As Wain says, set up multiple build targets. Select your project in the navigator area, then select the current target in the list of targets, right click on it, and select "duplicate". That will create a new target that does exactly the same thing.
You'll need to change the bundle ID, app name, etc.
Then you would select your current asset catalog, select the view menu>utilties>file inspector and set the target membership to just the current target. Select your new target, add a new asset catalog, and set it's target membership to only include the file in the new target.
Repeat this process for each version of the app that you want to build.

Creating two targets in XCode 4

I want to create two targets for my application iphone and ipad version.
My question is : Do I need to copy all the files from one target to another , because i found out that there are two AppDelegate files in my project, and what about resource and library files? This is the first time when i am trying to setup a multitarget project.
No, there is no need to copy source files. You can click on each file and tell Xcode which target they belong to (The Target Membership section of the File Inspector tab in the right pane).
Any files that are meant to be different (like the delegate classes you mention) obviously won't be added to both targets.

How to share files between two xcode projects in workspace?

I learnt about Xcode workspace .I know how to share the static library but i want to share the files between two xcode projects in workspace and is it possible to run multiple targets at a time?Can you provide me the information of how to do this.
Thanks in advance
Sharing files between projects in the same workspace is easy, even if the projects are on the same level (no subprojects):
Assume you want to share constants between Project1 and Project2, and these constants are defined in a file SharedConstants.swift, which is defined in Project1.
In order to be used in Project2, it must be compiled there.
Thus, activate in the project navigator Project2, select the target and open the Build Phases tab.
Open there Compile Sources by tapping the little triangle left.
Tap the + button below the listed sources for this target. This will show you a list of files of Project2. There you cannot select your shared constants, because they do not belong to this project.
However left bottom is a button Add other…
Tapping it will open a standard file selection window where you can select SharedConstants.swift from Project1.
After tapping Open, a 2nd window opens with a Destination: Copy items if needed checkbox.
Important: Do not check this box!
If you would check it, a copy of SharedConstants.swift would be used in Project2, and any changes that you make in Project1 would not be visible in Project2. Instead, it you uncheck it, only a reference to SharedConstants.swift in Project1 would be used in Project2, and any changes will affect both projects.
To share the files you can probably use the bundles
Targets are manipulated with Schemes in Xcode 4, you can launch several targets in the same time if you select the different destinations (with OS X you can probably have the same destination :) )
You'll see a little triangle below the stop button indicating that you can long-press it to select which operation should be terminated:
You can switch the console with the popover at the Debug area where you see the target name and icon - that's a button.
You can drag Xcode projects into other Xcode projects to nest them.
More info here:
How should I manage dependencies across projects in an Xcode workspace?

Resources