17

Coming to Swift from Delphi, I thought the View represented an app's GUI and the storyboard was a visual representation of the View's underlying code. The ViewController was the one and only object the View interacted with. When a popular tutorial says

In the old days developers used to create a separate interface file for the design of each view controller.

I'm thinking the "separate interface file" was the View file. But as I learn more, I'm getting confused. Beneath a screenshot of an empty Main.storyboard from a new application, the text says

The official storyboard terminology for a view controller is "scene," but you can use the terms interchangeably. The scene is what represents a view controller in the storyboard ... Here you see a single view controller containing an empty view.

So I'm seeing a "single view controller," not a view?? Confusion mounts when I note any views(?) displayed on a storyboard are called "View Controllers" in Swift.

So, what's the difference between a View and ViewController? How is a storyboard related? And what object "owns" something like a segue, which exists outside my (flawed) understanding of these concepts?

Al C
  • 5,175
  • 6
  • 44
  • 74
  • 1
    I can't answer that question as good as other people may do, so I will only comment here. The easiest way to tell the deference, is to think about the view controller as a container with one view, which will have other subviews. The view container will have some shiny callbacks you probably will need in some point of your application `func viewDidAppear(animated: Bool)` or `func viewDidLayoutSubviews()` for example. The view itself is where you can draw something or create a view hierarchy as in the view controller except you won't have all the callbacks the view controller has. – DevAndArtist Aug 04 '15 at 17:50

1 Answers1

19

Take a look at this post - What is the difference between a View and a View Controller?

This described it pretty well for me.

If you don't want to go to the link, here is a great description of the difference between a view and a view controller by Alex Wayne:

A view is an object that is drawn to the screen. It may also contain other views (subviews) that are inside it and move with it. Views can get touch events and change their visual state in response. Views are dumb, and do not know about the structure of your application, and are simply told to display themselves in some state.

A view controller is not drawable to the screen directly, it manages a group of view objects. View controllers usually have a single view with many subviews. The view controller manages the state of these views. A view controller is smart, and has knowledge of your application's inner workings. It tells the dumb view objects what to do and how to show themselves.

A view controller is the glue between your overall application and the screen. It controls the views that it owns according to the logic of your application.

Ben
  • 54,723
  • 49
  • 178
  • 224
Stefan DeClerck
  • 1,162
  • 2
  • 12
  • 22