Creating two targets in XCode 4 - ios

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.

Related

How to access one project classes from other project While using multiple project with one Workspace

I am using two different project within one workspace. I have one base(Say Unity-iPhone) project and i drag and drop another iOS project (Say InnerApp). Each file and folder are visible in base project as attached screenshot. I have also added the dependency in build phase of base project, and set the other linker flag and header search path.
Now I want to access the InnerApp classes and storyboard file in base project.
Now My problem is that, I want to launch the Inner App Main.storyboard into base project. But InnerApp classes are not accessible into base project.
Please guide me. Thanks.
You can follow some great step-by-step instructions on how to add static library dependencies while using multiple projects.
Use below urls -
Include one project into another one
Include static libraries into another one

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!

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.

Use an entire app as a dependency?

Without going into the why, I need to use an entire app for various classes and libraries it has and includes.
Is there a way I can use the entire project as a dependency? When I choose "static library target" I lose all the hundreds of classes in the "compile" step. Effectively I would like to be able to package the project such that I can use it elsewhere.
Is there an easy way to do this aside from building my new app out of the old app and changing the app name/launch targets?
You have to find a way to transport every element into the new XCode project. iOS app consists of:
main.m file - You probably won't need to copy that, as it's usually just one line.
Source files and headers for: appDelegate, ViewControllers etc. - I don't understand why you would "lose all the hundreds of classes" during compile time. You're the one that chooses what is to be included in the static library. Add all the header files you need to "Copy headers" in the static library target "Build Phases". Add all the source files into "Compile sources". There are many tutorials and StackOverflow posts on how to do that. (example: How can I create static library and can add just .a file on any project in ios)
Storyboards, xib files, *.plist files, images and other resources - you need to put these in a *.bundle file . Just create a new target (which is a bundle) and include all the needed resources in it. Then you'll have to find a way to use them in the new XCode project. For example setting the default *-info.plist or *.pch file: How to tell Xcode where my info.plist and .pch files are or setting the main storyboard.
So you end up with two files: one framework/static library and one bundle file. It shouldn't be that hard to configure new XCode project to use resources from the bundle and classes from the static library.
I'm not sure if I understood your question.
You can add your old app as a project to your workspace and add it as a "target dependency" to use it.
The easiest and safest way to do this is to copy the whole workspace and change the initial view controller.

Associate an image folder for a a specific target

I have created a projects witch contain two targets ( i have duplicate Target1 to have Target2). i have many images in the project. I would like to associate some images to one target and some others to the second target. I doing this by selecting one image.
my question:can i associate a fonder of images to a Target ? if yes how i can do this ?
thanks for your answers.
Yes, it's possible: well folder itself has no target membership but you can easily associate all files from one folder to one target and files from other folder to the other target. Files in these folders can have the same names of course.
You can have two separate folders on disk, let's say images_t1 and images_t2.
Drag images_t1 folder into project tree and when asked for "add to target" you only check Target1 checkbox. For images_t2 you only check Target2 checkbox - that's it.
I just retested it and target membership of imported files (inside the two folders) is correct.
But note, if you are planning to use this images with Interface Builder you might run into minor XCode bug - mixing images. There is a workaround for that, but it's not pretty. Check Xcode 4, Interface Builder, two targets with seperate .xib (image resources with same names).
This bug is visible only during .XIB editing - everything is fine once apps are compiled.

Resources