Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I properly add existing source code files to my Xcode project?

Tags:

xcode

iphone

I'm new to iPhone development and I'm still getting familiar with the Mac dev environment, including Xcode. I want to add some 3rd party code to my iPhone project, but when I add the "existing files" to my Xcode project, I'm presented with a dialog box that has far too many options that I don't understand and, as such, my project isn't working. When I #import headerfilename.h, I get a build error that reads headerfilename.h: No such file or directory.

alt text http://joecrotchett.com/images/misc/fileadd.jpg

  1. Can anyone explain to me what all these options mean or give me a link to some documentation that can? I'm having a hard time finding anything in Apple's docs.
  2. Which options do I want to choose to add existing source code files to my Xcode project? I should note that the source code files that I'm trying to add are located in my project/Classes/frameworkname/ directory.
  3. After they're added, do I need to reference this new code directory in my project settings anywhere (i.e. some kind of header file directory variable)?

Thanks so much!

Update: I found the following answers/responses on the apple dev forums that were very useful and helped me fix my issue...

To make it simple : - if you do not check the copy option, the file stay where it is. - if you check it, it is copied in your project folders In the first case (what it seems you are doing) you need to tell the compiler that the header files are in another directory : - project info -> build -> search paths -> User Header Search Path : add the directory from where you took the header file Hope this will help


You have discovered the most confusing dialog box that ever came out of Cupertino. Six years of Xcode, and this thing still is partly a mystery to me. To even get that far, I had to make many test projects to try and reverse-engineer what this thing does. The "Copy" box means that it will copy the files as they are right now, into the project. If this box is not checked, then it just references those files during a build and copies them as they are at THAT time. For source code, you want the Copy box checked.
The "relative to" is a total mystery to me and I can't help you with that. I usually leave it however it is already set. Does it mean relative to where they are on disk, or the arrangement in Xcode, or in the bundle? Who knows. The last 2 radio buttons SEEM to mean that it will either re-create the folder structure of the folder you are adding, or just put "fake" folders in Xcode that point to the real folders. This is probably your problem - you are adding source code that is not all at the top level, and when it goes to find it, it does not re-create the hierarchy. Others can supply a better way, hopefully, but what I would do is put all of the source in one folder and add that, using the Copy box. Then in Xcode you can make whatever bogus folders you want and put the source file names in those fake folders.

like image 943
BeachRunnerFred Avatar asked May 21 '10 15:05

BeachRunnerFred


1 Answers

This is from the Xcode user guide:

"The project navigator shows projects, groups, folders, and files:

The project or projects in your workspace window are the highest level of the hierarchy in the project navigator. Open the project’s disclosure triangle to see the groups, folders, and files in the project. Select the project to display the project editor, where you can view and edit project and target settings.

A group appears in the project navigator as a yellow folder icon. The group does not represent a folder on disk. Although you can organize your project in Xcode to reflect the organization of files on disk, moving files into and out of groups does not affect the content of the folders on disk, and moving files on disk into and out of folders does not affect the content of the groups in the project navigator.

A folder is a reference to a folder on disk and appears in the project navigator as a blue folder icon. The contents of the folder in the project navigator reflect the contents of the folder on disk. It’s important to note, however, that the files that appear in a folder icon in the project navigator are not part of your project unless you have added them to the project explicitly (in which case they appear directly under the project or in a group, as well as in the folder). You can view and edit the files in a folder, but to move files in and out of the folder you must use the Finder.

A file in the project navigator is a reference to a file on disk."

like image 138
Sam Clewlow Avatar answered Sep 20 '22 17:09

Sam Clewlow