Component - First iOS app
This is the simplest iOS app screen. It shows a greeting message and a button. When you tap the button, the message changes. This helps beginners see how to build and update a screen in iOS using SwiftUI.
This is the simplest iOS app screen. It shows a greeting message and a button. When you tap the button, the message changes. This helps beginners see how to build and update a screen in iOS using SwiftUI.
ContentView ├── VStack │ ├── Text │ └── Button
Text view do in a basic SwiftUI iOS app?Text in SwiftUIText view is used to show words or sentences on the screen.Button, which handles taps, Text only displays static text.Text shows text [OK]Button { action } label: { Text("label") }.struct ContentView: View {
@State private var count = 0
var body: some View {
VStack {
Text("Count: \(count)")
Button("Increment") {
count += 1
}
}
}
}count is marked with @State, so changes update the UI.count is 0, so text shows "Count: 0" and button labeled "Increment" is visible.struct ContentView: View {
var body: some View {
Button("Click me") {
print("Clicked")
}
}
}body computed property implicitly returns the view using @ViewBuilder.Button("Click me") { print("Clicked") } is valid; no explicit return needed even for multi-line expressions.body uses implicit return via ViewBuilder [OK]return is required@ViewBuilder must be marked explicitlymessage must be a @State variable.message to "Button tapped!" and the UI reflects this change.@State private var, a VStack with Text(message), and a button with label and action correctly.Pass the test and this pattern moves unknown