How to Importing files from one project to another - xcode

I want to copy some files "Classes" from another project to my current project, but when I run it I get dozen of errors, its seem there are some steps to copying file from one project to another project using Xcode ,
I can make a collection of files "Classes" accessible in my project?
One project is Objective c, the another one seems to be Objective C++

Individual Files
Organize your files
Place the files you will need at a location that is accessible by the Xcode project. Usually, you place these files is a directory below your Xcode project, but that is absolutely not necessary.
Drag & drop
Grab all the files you need and drop them onto your project organizer. You will be prompted with this dialog, to which the settings should look like this (ensure that your target is selected):
Projects
If you want to include a Cocoa Touch Static Library, in the form of an Xcode project, drag & drop will suffice.

No there are not exactly steps we need to follow. Just make sure all dependencies are fulfilled while importing classes from other project. Don't forget to click at checkbox Copy files if needed so that Xcode can make separate copy for your project.
In order to import files in your project click following sequence:
command + option + A
or you can also add files by
Xcode -> File -> Add files to "Project Name"

Related

In Xcode how do I create a new workspace and add 1 project to it so that I can see the project and its files?

In Xcode how do I create a new workspace and add 1 project to it so that I can see the project and its files?
If I just drag in the project, all I can see is the project it cannot be expanded, I cannot see the files. Also, is there anyway to copy over existing schemes from the project so that they can be used in the workspace?
First choose file > new > Workspace...
Then, you must first, and this is important, you must first close the project that you want to drag in. Than drag in the .xcodeproj file from the finder to your new workspace. Then it will appear properly and expand to show all of its files and your schemes will be available.
Although the accepted answer is correct, there is an alternate way to accomplish the same thing, and it is arguably easier/more straightforward. You can just open up the project in Xcode and click File -> Save as Workspace...
Bam! You now have a workspace with 1 project in it, as requested.
Just FYI, 2020, Apple recently added a thing,
make your workspace, exit it and
make your new project. in fact when you enter the name to save the project,
they added this option:
just select the workspace you wish to add it to.
Besides all above solutions you can use this alternative. Let's say you have a workspace and a project that you want to add to that workspace.
Close your project.
Open your workspace.
Option + Click in the Project navigator. Make sure you are clicking on an empty area, not on the existing files or folders.
In the context menu, select "Add files to your workspace...".
Finally select your project xcodeproj file on you disk.
Have a nice project 😉,
Add project into workspace
As alternative
- Close a project that you are going to add to a workspace
- Open Project Navigator -> Right click -> Add Files to "<workspace_name>"...

XCode SubProject configuration

due to working needs, I need to integrate an xcodeproj into my existing project as subproject.
The structure of my two projects is the following
Structure of the two projects
What is the best practice to integrate (no cocoapods) the subProject into my main project?
I have done the following steps as you can see from the picture below:
Integration Steps
I have copied the folder and all the files to my MainProject
folder.
In XCode I have added files to MainProject and then I have choose
the "SubProject.xcodeproj" and I can see the structure in the
project navigator.
I have added into the "Search Header Path" the following sentence:
"${SRCROOT}/../SubProject" with recursive search.
I am not be able to import into my main project the header of the sub project. How can I solve my situation? What I am missing?
Is not clear what you mean with "Integrate a sub project". What to you want achieve? A single target or every project should build a different binary?
First of all I would suggest you to put both project in the same folder, in your example they are both inside the Desktop folder so this is ok.
As second step you should create a workspace, and add both project to this workspace. There is no need of moving folders around, just drag the project icon inside xCode, just below the workspace icon.

Xcode easily add multiple files to a target

I've created a new target for unit tests in Xcode 4.2, and obviously i need to bring in certain application files into that target. But there is a lot, and it seems cumbersome to click each .m file then click TargetMembership and tick the new target box.
Is there an easier way to do this in Xcode that i'm missing?
Thanks
I though't i'd return to this with an improved answer. It's still difficult to do this via Xcode main interface, as if you filter for .m and try and do CMD-A to select all, it selects the folders too, so you can't add these to the target.
However, if you go to Project Settings > Build Phases > Compile Sources. You can click the + button, filter .m files, and you can CMD-A to select all here.
This works.
If the files are all in a single directory, delete the directory from the project (remove reference only), then re-add it. Xcode will ask you which targets you want the files to be added to when you re-add it.
Select all the .m files in the "Project Editor" (cmd-1), show the "Utilities View" (opt-cmd-0) and click the new target in "Target Membership". Be careful not to select files that do not belong to a project such as .h files.
create a static or dynamic library, to which both executables link.
If you duplicate and existing target instead of creating a new one from scratch, all the existing files will be a member of the new(duplicated) target as well.
In 2016 you can now use both an AppTest and LogicTest target so you don't have to fiddle around with target settings.
You don't need to add any files to the AppTest target since it will have access to all main target files, and put pure logic tests in LogicTest.
In Xcode 10
You can also select multiple files in Project navigator and then, in the "Inspectors" right side pane you can modify Target Membership:

Creating Xcode project from command line

My question is how can I create and Xcode project from the command line. By create I don't mean building a project. I mean how can i create a project forlder i.e shift + cmd + N.
Cmake will create Xcode projects along with any other type of build file you could desire. It is heavily customizable and can handle multiple targets, dependencies, linking, and any other property you could image. It has a steep learning curve but is a very very powerful tool. We currently use cmake to genererate both the Xcode and visual studio solution from the same code base.
The simplest example of cmake is $cmake -G "Xcode" ...args... this would create and all all the nessecary files to your project from your args.
Here is the main page: http://www.cmake.org
An Xcode project consists of the source files for the project and and .xcodeproj folder (it looks like a file, but it's actually a bundle, i.e. a folder and files within it treated by Finder as a single object).
If you look inside the .xcodeproj folder (you can do this with the terminal app or you can right-click on the .xcodeproj bundle and select "Show Package Contents") you will see several files. The only file that matter is project.pbxproj. The format of this file is undocumented, but it is a text file and if you take a look at it, the format doesn't seem too complicated.
To generate a project you need to create a folder with an appropriate .xcodeproj folder within it and an appropriate project.pbxproj file inside that folder. If your project needs are simple, you could always start with a canned project.pbxproj file generated by Xcode and stick it in your .xcodeproj folder.

Xcode Different Resources For Different Targets

I am developing an iPhone app and there will be a Full as well as a Lite version of that app. In order get both bundles from the same source code and Xcode project I added another target to the Xcode project.
Now, I want to have the Lite target copy only a subset of the resource files to the bundle. But, Xcode won't simply let me delete individual files from the "Copy Files to Bundle" build step, since I imported all my resources as folder references. I need this in order to maintain a directory structure in the resources directory.
How do I solve this problem? Any suggestions or ideas are greatly appreciated!
In the left-hand panel of Xcode, right-click on the "Groups & Files" bar at the top. Check "Target Membership".
Now you'll see a tick against every file that should be included in your current build target. Untick the ones you don't want, switch to your other target, and repeat.
Instead of manipulating the "Copy Bundle Resources" step of your target, you can right-click resource files or groups (folders), choose "Get Info," and selectively leave stuff out of your Lite build under the Targets tabs of the info window for the file(s) you selected. Doing this on a group (folder) recurses the changes, so using resource groups (folders) is a nice easy way to make separate resources collections for separate builds.

Resources