What Is SwiftUI
Part of the Introduction to SwiftUI section of Coddy's Swift journey. Lesson 1 of 50.
SwiftUI is Apple's framework for building app screens in Swift. You describe what the screen shows, and SwiftUI draws it and redraws it whenever your data changes.
A piece of screen is a view: a struct that conforms to View and has a body property. The body returns what the view shows:
struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}Text is a view that shows a line of text. some View means the body returns one particular kind of view, and Swift works out which kind from the code inside.
The preview next to the editor renders your view each time you change the code, so you see the result of every edit.
Challenge
BeginnerChange the text so the screen shows Hello, SwiftUI! instead of Hello, World!.
Try it yourself
import SwiftUI
@main
struct CoddyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Introduction to SwiftUI
Practice on your own: Swift playground