views:

413

answers:

2

I'm working with xcode and I have classes associated with other projects that I want to be included in new projects. I realize that the #import will do the job technically (although what should i do if it's out of the project root folder). But what do I do if I want to include the class "properly" --basically so i can double click and edit out of the main project window where you can see all your files and such.

I guess I'm just looking for the best and/or proper way to include/import (into the project) .h and .m files that I've already created outside of the current project I'm working on. Taking into consideration that I may want to modify the class from the original without subclassing. Hopefully this makes sense.

Thanks,

Nick

A: 

Might be worth thinking about how to make the classes into a private framework - then you can import that as another dependency each time. Alternatively you could use a separate version control system location to store the shared classes and just check that out into the project folder.

AlBlue
what I'm doing now is creating a blank class in the new project and then copying and pasting code from old project classes, which is somewhat lame, isn't there an "import" command or something similar to complete the same task? (aside from the #import)
nickthedude
+2  A: 

Xcode project file organization doesn't reflect the data files on disk. Files can be added to a project from anywhere in the file system. When you add the files, choosing not to copy the files to the current project's directory means that the original files are used. Selecting one of these files in Xcode for editing will alter the original file in that other project. When returning to that other project, Xcode will use the edited files in any further work.

This type of use can be quite handy while working on multiple projects with some shared code. Yet, it can also cause headaches for a versioning system.

Mr. Berna
That is helpful however I'm still unsure of how I actually "add the files" as you put it. I'm really new at this so if you could be as explicit as possible about how you would go about doing this I would really appreciate it.Thanks,Nick
nickthedude
With a project open, select "Add to Project..." from the "Project" menu. Use the resulting dialog sheet to find the files you want to add. A second dialog sheet will allow you to set options, make sure to set the "copy items into destination group's folder" option appropriately. If this option is on, a new copy of the files will be made in the project's folder on the disk. If this option is off, the original files will be added to the project.
Mr. Berna
ok that is what I thought, it was 'greying' out my class files because I had already copied them into the project folder. thanks for the clarification. You rock!Nick
nickthedude