Re: Two view controllers in one set of files (Noob
question)



At 12:57 -0400 25/3/09, I. Savant wrote:
You can certainly have more than one class declared and implemented
in the same .h/.m files. You can also have multiple controllers within
the same XIB. Wherever your classes are declared/implemented, they
show up as "available" in Interface Builder as individual classes, so
when you instantiate them, they appear as if they were
declared/implemented in different files. IB does not care.

This is not strictly true - the interface for the class must be in a .h file. Interface Builder does not appear to search implementation (.m, .mm, etc) files.

May I ask why you don't want separate source code files for separate
classes? If they're all heavily related (such as NSTabView /
NSTabViewItem), it makes some sense, but if they're separate
controllers, you're just cluttering your files. It's far easier when
you have one class (or one small group of two or three related
classes) in one file because you can easily find them in your source
tree. Combining lots of source from multiple medium-to-large classes
in a single file will undoubtedly make navigating your code harder,
and will probably slow down the editor. It's easier in this case just
to separate your classes into their own files.

It is clearly the "Cocoa Way" to have one class per .h/.m file pair. And probably even could be said it is the "OO Way".

It is, as you note, sometimes sensible to have tightly coupled classes in the same file. Probably my most common case for this is NSWindow/NSWindowController subclass pairs (but I'm doing lots of special look NSPanels from a background app so that might explain it). Often the NSPanel subclass is almost trivial.

But I'm a bit uncertain when you would have two tightly coupled controllers that could not simply be a single controller, so perhaps the OP would like to post the reason why he wants them together (the reason why you are ...

asking a question is often helpful in determining the best answer which is not always the answer to the question posted).

Enjoy,
Peter.

--
Run macros from your iPhone with Keyboard Maestro Control!
or take a break with Derzle for your iPhone

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
Aragom Space War <http://www.stairways.com/iphone/aragom> Don't get killed!
Derzle <http://www.stairways.com/iphone/derzle> Enjoy a relaxing puzzle.
<http://www.stairways.com/> <http://download.stairways.com/>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us

This email sent to maillists@xxxxxxxxx



Privacy