NSWindowController, NSViewController and UIViewController

With introduction of the iPhone SDK, Apple seemed to introduce new programming model or new way of organizing UIs and coding structure.
Due to them programming for iPhone and iPod touch looks different than that for Mac. One strength of iPhone SDK is that Mac programmers can transfer their skill set to iPhone very easily. However, because they are very similar, it is also prone to forget how they have written codes for the Mac. So, somehow Apple should design upcoming version of SDKs for Mac and the iPhone to make them abide by same programming model and flow.

One of those is view controllers. With iPhone SDK and Leopard SDK, they introduced view controllers, or NSViewController and UIViewController. As their names suggest what they do is to manage views. Although their purpose is explained quite thoroughly at KATI’s blog, it was a little difficult for me to read it. So, I would like to briefly define what they are.

The view controllers are for managing views. Current trend in UI design is Single Window, Multiple View. What it means is that there is one Window and inside of it, different group of views designed for different purpose can be swapped in and out. So, the View Controllers handles these for programmers for well-established pattern.

Currently view controllers are very important for iPhone and iPod touch programming, because the platform is based on Single-Window and Multiple View model. However, it doesn’t seem to me that using view controller is very popular for Mac. ( Again, it is a new trend. So, people who want to adopt it will use the view controllers. I hope that Apple provides some sample using the view controllers. ( Did they do so already? ) However, people can always take a look at sample codes for iPhone and get the idea.

Then, how about the window controller like NSWindowController? Its counterpart, UIWindowController doesn’t exist for the iPhone and iPod touch environment, because there is only one window for those environment.
Unlike view controllers, the NSWindowController is for document based programs. Well, document based program can use multiple window. So, it is reasonable to think that NSWindowController is for document based programs as Apple’s document says.

Here, I would like to mention about the hierarchy of NSWindow, NSView, and UIView, UIWindow. As you know, it is a little weird that UIWindow is subclass of UIView, while on the Mac it is opposite.
How to understand this? On a Mac, it is like that view is the region of scene you can see through a window. So, the window provides a view. So, NSView is a subclass of is located under the NSWindow in its hierarchy. However, for iPhone, view is the whole scene which is outside of a window. Very wide seashore, very tall and wide mountain, open crop field, and so on. They are the view. However, window restrict how much you can see the view or whole scene. So, the window class is a subclass of the view class.

Well, things can be different how we see the world! :)

5 responses to this post.

  1. Posted by Craig on April 15, 2009 at 7:35 PM

    Nice little overview. i am just starting out in iPhone dev and the whole UIView vs UIViewController, xib, nib, nill, getter objective C and Cocoa learning curve is steep. Thanks for our insights.

    Reply

  2. Posted by Scott on April 1, 2010 at 8:37 PM

    Actually, UIWindowController does exist on the iPhone OS. It just isn’t part of the published API, but if you look at the stack traces for the EXC_BAD_ACCESS bugs that show up trying to do one modal controller immediately on top of another one, you will see UIWindowController on the stack.

    Reply

    • Posted by jongampark on April 2, 2010 at 7:23 AM

      Thank you for mentioning about the existence of UIWindowController. However, does it have the same purpose as NSWindowController?

      Reply

  3. Posted by malaba on January 25, 2012 at 1:54 AM

    NSView is *not* a subclass of the NSWindow

    Reply

    • Posted by jongampark on January 25, 2012 at 8:09 AM

      Correction : NSView is located under NSWindow in its hierarchy.
      You can see that I mentioned UIWindow and UIView earlier than about NSView/NSWindow.
      It was just habitual mumbling about its hierarchy. Did you attend WWDC session or watched video which explains differences between Mac / iOS framework?
      It is explained there, although it can be also found in the documentation and headers.
      However, at that time what was being focused is their difference of hierarchy, and I iterated that. OK?

      Reply

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: