views:

66

answers:

3

An iPad project I have been working on has become bloated with a huge number of files. The application is a prototype and we are considering ways to prevent this when we rewrite it.

One of the members of our team suggests dividing all of the components into separate Xcode projects which will be included in a master Xcode project.

Is this a good idea? What are the reasons, if any, to avoid dividing features/components/controls into separate Xcode projects?

A: 

An Xcode project can have any number of build targets within it, and you can arbitrarily group source files into folders. What makes you think that multiple projects are necessary?

NSResponder
Maybe he doesn't like to see all the folders and files?
Kinderchocolate
The idea is to enforce the separation of the components.
titaniumdecoy
+1  A: 

You can add a subsidiary project file to a master project file in Xcode. Just choose "Add File" and add it. When Xcode builds the master it will build the subsidiary as well if needed.

I use a similar system. I often break a project into sub projects just so I can focus on and enforce encapsulation. I write the data model first, then add the app delegate, then specific UI elements. I add each project to the next in turn. This also allows me to go back and change things without as much risk of breaking.

Really, a properly designed objective-c app should be easy to decompose into multiple project. Ideally, all the components are so encapsulate that they don't need any others save the data model.

TechZen
How does this work? I tried adding another Xcode project to a master Xcode project but when I compiled none of the files in the other project could be found.
titaniumdecoy
Add the external project document by reference instead of copying. The paths to the projects source files is relative to the location of the project document itself. If you use a copy of the project file outside the project directory, Xcode can't locate the files.
TechZen
+2  A: 

We have put some of the code in its own project, building a framework which we link against at some of the other projects. It's sometimes annoying that you won't see the implementation files of the framework code right away in another project (by cmd+clicking or cmd+shift+D, or whatever you do normally to navigate). Xcode will only show you the header, you'll have to open the other project and find your file there manually. Not a big deal, but if you look up the code often, it will bother you.

A real problem is that you change the scope of some operations. Stuff like "Find in project" will work on a different file set, which might not be what you want sometimes (trying to find where this method is called / key is used in your whole code, or something); well, there remains Finder / find, so it might be okay. Refactoring is not - all the renaming stuff just breaks, as it will change only the code of the current project, but not of projects referencing this one. If you change interfaces often, better avoid splitting up the project.

A good thing is that you will get less conflicts on your .xcodeproj files (if stored in a shared repository) as someone removing a file from project X won't create a conflict with someone else adding a target on project Y, which where previously the same .xcodeproj (not exactly sure this is a conflict case, but there definitely are some).

w.m