import SwiftUI
struct ContentView: View {
@State private var showExplanation = false
var body: some View {
VStack(alignment: .leading, spacing: 16) {
Text("Swift Safety and Speed")
.font(.title)
.bold()
Text("Why Swift?")
.font(.headline)
VStack(alignment: .leading, spacing: 8) {
Text("• Safe code: Swift helps avoid common errors like null pointers.")
Text("• Fast performance: Swift is optimized to run quickly on devices.")
}
Text("Example:")
.font(.headline)
Text("let x: Int = 5\nlet y = x + 10")
.font(.system(.body, design: .monospaced))
.padding(8)
.background(Color.gray.opacity(0.1))
.cornerRadius(5)
Button(action: {
showExplanation.toggle()
}) {
Text(showExplanation ? "Hide Explanation" : "Show Explanation")
.foregroundColor(.blue)
}
if showExplanation {
Text("Swift is designed to catch mistakes early and run your code fast, making apps safer and smoother.")
.font(.body)
.padding(.top, 8)
}
Spacer()
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}This screen uses a vertical stack to organize the content clearly.
We show a title and a subtitle, then two bullet points explaining safety and speed in simple words.
The Swift code example uses a monospaced font and a light background to look like code.
The button toggles showing or hiding the explanation text below it.
This approach keeps the UI simple and friendly, helping beginners understand why Swift is safe and fast.