Creating Xcode project from command line - xcode

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.

Related

Xcode - sort files by name, put folders (groups) first

When clicking on Sort by Name, Xcode sorts my files and folders mixed. This results in dragging the folders back manually to the front each and every time, and that's pretty tedious.
With Sort by Type, folders go to the bottom which is even worse.
Is there a way to sort the folders and then the files alphabetically?
It is not possible with UI, but you can try to write a custom script that does that. There are libraries that are able to work with the Xcode project format, for example CocoaPods Xcodeproj. This should be a good starting point.
When working on a Swift Package, the file structure is automatically ordered so that folders come first. Here's how to take advantage of this with a normal Xcode project (here's the source of this info):
Make a new Swift package
Create a new Xcode project using the package's project folder as the folder
Open the new project you just created
Work within this project, but create the files inside the Swift package

How to Importing files from one project to another

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"

Changing the name of main folder in Xcode project

This is not the first time I've had trouble with this and I suspect not the last time either. Despite having learned many frameworks inside out I still find the organizational structure of a simple xcode project elusive. I simply wanted to retitle a project from CATouchSynth to ABTouchSynth. A while ago I discovered that if you click on the Project folder in project navigator and than change the name in the Identity and Type section it will rename many of the relevant files and directories to the new name. However, there is one main folder inside the folder on your computer that doesn't change and still has the old name. I could see no way to change this folder name through Xcode and so I renamed it manually from finder. This turned all of my source files and assets red so I manually "relinked" them in xcode and they are now non-red and seemingly linked with the newly named folder. However I am getting several compile-time errors talking about the old folder name but I have no clue what Xcode is referring too. The errors look like this
It seemed as if derived data was an issue so I deleted the derived data folder from Xcode and I still get these errors. Has anyone experienced this before and what can I do to ressurrect my project?
Note: Before doing any changes do backup your project folder. This is seriously recommended.
Follow the steps below to rename the source folder of your project –
Close XCode.
Rename the Source Folder.
Right click the project bundle .xcodeproj file and select “Show Package Contents” from the context menu. Open the .pbxproj file with any text editor (Xcode).
This step should be done with extreme caution. Search and replace any occurrence of the original folder name with the new folder name.
Save and Close the file.
Open XCode project.
The error is happening at build time during the compile phase, so you will have to go into the app target's Compile Sources build phase, remove all those .m files, and add them again.

Copy .dylib library from one xcode project to another

So I have one Xcode project that I downloaded that comes with a ~.dylib file and a folder titled 'include' that comes with all the files for that library.
What I want to do is copy these files into another XCode project.
However I don't know how to get XCode to recognize the ~.dylib file. Right now XCode allows me to create instances of classes defined in this library but whenever I try to call any associated methods it says it can't find those methods and gives an error (presumably because the ~.dylib file is not linked properly.
Try this: Select your project file, choose your target, Build Settings, and search for "Library Search Paths", and add the path to your dylib file to it.

want to use Xcode 4 for everything, how to add folder in project navigator?

I'd like to move my web dev editing to Xcode 4 (currently using textmate). I have a couple of simple questions that are clearly a lack of experience on my end.
In Xcode's Project Navigator, how do I add a folder to the shown directory tree? Currently, I add via terminal and do File -> Add Files
Is there any way to tell Xcode to see the file system as the file system and not as references?
a less likely thing:
Is there any way to bring up a console within the context of a folder in project navigator (would like to be able to run grep again small portion or something)?
thx
I can answer the first question. Adding a folder of files to a project is the same as adding individual files. Choose File > Add Files in Xcode. When you add a folder of files to a project, you should see something like the following screenshot:
Create groups if you need to access the files in Xcode, such as adding a folder of source code files. Create folder references if you don't need to access the files in Xcode, such as adding a folder of audio files.
You can also add folders to the project navigator by selecting a file or folder in the project navigator, right-clicking, and choosing New Group.
As far as I know, Xcode won't mirror the filesystem as an Xcode tree (anyone correct me id I'm wrong). Wanting to have an identical structure is quite some work. I use to first place the files hierarchically in the file-system, then I mimic the same structure in Xcode.
This requires some attention since Xcode 4.1 not always writes new classes to the place you told him to - they may prefer to land in the highest level of the Xcode project.
I had similar thoughts and started a thread, might be helpful for further reading
Your second question: sorry, can't help you there.

Resources