SwiftUI Fundamentals

Feb 28 2023 · Swift 5.7, macOS Venture 13.1, Xcode 14.2

Part 1: SwiftUI Views

02. The View Protocol

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 01. Introduction Next episode: 03. Modifiers

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 02. The View Protocol

To learn more about the Swift features supporting SwiftUI, check out these chapters from our book, Swift Apprentice:

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

The basis for everything you’ll do in SwiftUI is the View protocol. Each “view” in swiftUI will be a value type, a struct, conforming to the View protocol. View has one requirement: the Body property, which provides some sort of UI element to be rendered.

Text("Howdy, World!")
}
  ❌.padding()
Text("Howdy, world!")
  Image(systemName: "swift")
Text("Hello, World!")
Image(systemName: "swift")
VStack {...}
public protocol View {
  associatedtype Body : View

  @ViewBuilder var body: Self.Body { get }
}
body: ❌View {...}
> Undo!