Was ist eine View?
Lernen Sie das View-Protokoll und die berechnete Eigenschaft body kennen.
Was ist eine View? ist eine kostenlose SwiftUI Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des SwiftUI Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der SwiftUI Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
Everything Is a View
In SwiftUI, almost everything you see on screen is a view. Text, images, buttons, and even your whole screen are all views. 📱
The View Protocol
A view is any type that conforms to the View protocol. Conforming means you promise to describe what should appear on screen.
struct ContentView: View {
var body: some View {
Text("Hello!")
}
}Views Are Structs
Most SwiftUI views are simple structs. They are lightweight value types, so SwiftUI can create and discard them cheaply as your UI changes.
The body Requirement
The View protocol has one job for you: provide a body property. It is where you describe the view's content.
struct ContentView: View {
var body: some View {
Text("Welcome")
}
}body Is Computed
The body is a computed property, not stored. SwiftUI reads it whenever it needs to redraw, so it always reflects your latest code.
What some View Means
The return type some View says body returns one specific view type, but you do not have to spell out which. The compiler figures it out.
var body: some View {
Text("Opaque type magic")
}One View, Many Pieces
A single view's body often combines many smaller views. The whole arrangement is still treated as one view from the outside. 🧩
Views Describe, Not Draw
You never paint pixels yourself. A view simply describes what it wants, and SwiftUI decides how to render it efficiently.
Views Are Cheap and Disposable
Because views are value types, SwiftUI recreates them constantly. Do not store heavy work in a view; keep its body fast and simple.
Composing Custom Views
You build your app by writing your own custom views. Each one is a struct conforming to View, just like the built-in ones.
struct GreetingView: View {
var body: some View {
Text("Hi there")
}
}Reusing Your Views
Once you define a view, you can drop it anywhere just by its name. This reuse keeps your UI consistent and your code tidy.
var body: some View {
GreetingView()
}Quick Check
Let's confirm what makes a type a SwiftUI view.
Recap: What Is a View?
A view is a struct that conforms to View and provides a body of type some View. Views describe content, are cheap, and compose into your whole UI. 🎉
Häufig gestellte Fragen
Ist die Lektion „Was ist eine View?“ kostenlos?
Ja — der vollständige Text von „Was ist eine View?“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des SwiftUI Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der SwiftUI Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Was ist eine View?“?
Lernen Sie das View-Protokoll und die berechnete Eigenschaft body kennen. Du übst SwiftUI Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um SwiftUI Academy zu starten?
Keine Vorkenntnisse erforderlich. SwiftUI Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „Was ist eine View?“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser SwiftUI Academy-Lektion Code schreiben und ausführen?
Ja. Jede SwiftUI Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Was ist eine View?
- Text auf dem Bildschirm anzeigen
- View-Modifier kennenlernen
- Die View-Hierarchie lesen