

That’s time and energy saved, which you can now devote to drinking beer! Window Controller or View Controller? If a File Browser with a hierarchical view on the left is controlled by a single view controller, you can use it in another application that needs a similar view.
#PICTURE VIEWER FOR MAC OS CODE#
This makes your code way easier to organize.Īnother benefit is that view controllers are easy to reuse in other applications. The view controllers take care of those smaller units, while the window controller handles window-specific tasks like resizing or closing the window. View controllers allow you to split the content of your window into logical units. After OS X 10.10, however, view controllers became very useful as building blocks for more complex user interfaces. That means, for example, that if you had a button on a view controller’s view, the controller would not receive its events. View controllers have been around for a while (Apple introduced them with OS X 10.5), but before OS X 10.10 they weren’t part of the responder chain. In macOS, view controllers are implemented as subclasses of NSViewController.
#PICTURE VIEWER FOR MAC OS WINDOWS#
There’s no starter project - you’ll build a great app from scratch! You might like to read Gabriel Miro’s excellent tutorial on windows and window controllers before embarking upon this view controllers tutorial, but it’s not a requirement.Įnough introduction - let’s kick off with some theory! Introducing View ControllersĪ view controller is responsible for managing a view and its subviews. To follow this tutorial you’ll need the most recent version of macOS and Xcode installed on your mac.

You’ll see how the life cycle methods allow you to hook into important events for the UI of your app, together with how view controllers compare with window controllers. In this macOS view controllers tutorial you’ll discover the wide range of functionality that is baked into vanilla view controllers, along with learning how you can create your own view controller subclasses to build up your app in an easy-to-understand manner. View controllers are responsible for hooking up the model layer to the view layer, and have an incredibly important role in the architecture of your macOS app. Apple has designed the frameworks available on macOS around the Model-View-Controller design pattern, and as such has provided various controller objects that are responsible for managing the UI. This helps keep code maintainable and easy to understand. When writing any code, it’s important to get clear separation of concerns - functionality should be split out into appropriate smaller classes.
