tags:

views:

141

answers:

3

Looking for the best way to set-up an iPhone project in XCode ... namely:

  1. What is the preferred project template to start with (e.g View-Based or Windows-Based application)?

  2. What folder structure should I create in XCode to manage the project? For example, under "Classes" is it a preferred practice to add Models, Views and Controllers sub-folders?

Any other best practices, tips, etc... would be appreciated.

Thanks

A: 

Take the most "complicated" template, based on your level of knowledge. I usually start out with the "Window-based application" myself, and add components one at a time from there.

I keep all of my code (.m/.h/.c/etc) in the "Classes" folder and only rarely add subdirectories to it. One exception is a "Generated" subdirectory for classes generated from Core Data entities.

When I create a new UIViewController subclass, I rename the resulting .xib to remove the "Controller" part; i.e. MyViewController.m gets paired with MyView.xib. (I think MyViewController.xib reads funny, as the xib isn't for the controller, it's for the view.) I also move the .xibs into their own directory next to the project file to keep things tidy.

Shaggy Frog
A: 

There is no "best" template. Window-based is the most basic, while View-based starts you out with a view and a view controller.

I'm with Shaggy Frog on renaming xib files to not have "controller" in the name. However, I like to create groups to logically separate functionality, and in those groups I place view controller code along with the xib files those view controllers use. Then you know what belongs with what.

I also like a create a top-level "Application" group into which I put the app delegate, main xib file (if any), pch file, info.plist, app icon, Default.png and other things related just to the application so they are all easy to find - after you add a number of files each of those things can get lost in giant lists of stuff.

Basically organize things so you can find them, a structure that makes sense to you might not to someone else.

Kendall Helmstetter Gelner
A: 

Window-based provides you with the most flexibility, and is probably what you want to choose after you've got a couple of projects under your belt. I find with the other templates that I'm usually removing too much code, and it would be quicker to just start from scratch.

I usually setup my projects by creating 4 subfolders under Classes: "Views", "View Controllers", "Model Objects" and "Helpers". Model objects contains all the basic object types, where as Helpers contains things like utility classes or similar. Sometimes, where relevant, I will also create a Table Cells folder underneath both Views and View Controllers. I move MainWindow.xib to the Views folder.

If the project is large, I will sometimes also have sub-folders for the Views and View Controllers based on the UITabBarController tabs. So if I have 5 tabs, then the Views folder will have 5 sub-folders, as will the View Controllers folder. I find this helps to keep everything logically together in the same place.

One other thing I do is create an Images folder under Resources, otherwise that folder gets way too cluttered very quickly.

alku83