SwiftUI Basics: Views, Modifiers, Stacks and Your First Screen

Swift 60 min min read Updated: Nov 21, 2026 Beginner
SwiftUI Basics: Views, Modifiers, Stacks and Your First Screen
Beginner Topic 1 of 3
About the code in this lesson SwiftUI runs only on Apple platforms with Xcode, so the SwiftUI code here is shown without output and was not run in this course's test setup. Build and run it in Xcode to see the result.

What Is SwiftUI?

SwiftUI is Apple's framework for building interfaces by describing what the screen should look like. You write small View structs, and SwiftUI draws and updates them.

Your First View

swift import SwiftUI struct ContentView: View { var body: some View { Text("Hello, Swift!") .font(.largeTitle) .foregroundStyle(.blue) } }

body is the one required property. It returns some View, the opaque type you learned earlier. Each .font and .foregroundStyle is a modifier that returns a new, changed view.

Modifier Order Matters

swift Text("Hi") .padding() .background(.yellow) // yellow covers the text plus padding Text("Hi") .background(.yellow) // yellow covers only the text .padding()

Stacks

ViewArranges children
VStackTop to bottom
HStackLeft to right
ZStackLayered, back to front
SpacerFlexible empty space
swift struct ProfileCard: View { var body: some View { HStack(spacing: 12) { Image(systemName: "person.circle.fill") .font(.system(size: 48)) VStack(alignment: .leading) { Text("Asha").font(.headline) Text("iOS Developer").font(.subheadline).foregroundStyle(.secondary) } Spacer() Button("Follow") { print("tapped") } .buttonStyle(.borderedProminent) } .padding() } }

Previews

swift #Preview { ProfileCard() }
Learn by changing In Xcode, change a modifier and watch the preview update. This is the fastest way to learn SwiftUI.

Common Mistakes

  • Putting a modifier before another when the order changes the look
  • Making one huge body instead of small views
  • Forgetting that views are structs, not classes

Practice

  1. Build a card with an image, a title and a subtitle
  2. Add a Spacer to push a button to the right
  3. Swap the order of padding and background and compare

Conclusion

SwiftUI screens are small structs with a body. Modifiers and stacks are your main tools.

Quick Summary: View; body; modifiers; stacks; previews.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators