|
prompt,output |
|
Create a SwiftUI view with a button that changes text on tap, |
|
|
|
struct ContentView: View { |
|
@State private var text = ""Hello, World!"" |
|
|
|
var body: some View { |
|
VStack { |
|
Text(text) |
|
.font(.largeTitle) |
|
Button(""Tap me"") { |
|
text = ""Button Tapped!"" |
|
} |
|
.padding() |
|
} |
|
} |
|
} |
|
Create a SwiftUI view with a TextField and a Text showing its value, |
|
|
|
struct ContentView: View { |
|
@State private var name = """" |
|
|
|
var body: some View { |
|
VStack { |
|
TextField(""Enter your name"", text: $name) |
|
.textFieldStyle(RoundedBorderTextFieldStyle()) |
|
.padding() |
|
Text(""Hello, \(name)!"") |
|
.font(.title) |
|
} |
|
.padding() |
|
} |
|
} |
|
Create a SwiftUI List with 5 items, |
|
|
|
struct ContentView: View { |
|
let items = [""Item 1"", ""Item 2"", ""Item 3"", ""Item 4"", ""Item 5""] |
|
|
|
var body: some View { |
|
List(items, id: \ .self) { item in |
|
Text(item) |
|
} |
|
} |
|
} |
|
Create a SwiftUI view with a toggle switch, |
|
|
|
struct ContentView: View { |
|
@State private var isOn = false |
|
|
|
var body: some View { |
|
VStack { |
|
Toggle(""Enable Feature"", isOn: $isOn) |
|
.padding() |
|
Text(isOn ? ""Feature is ON"" : ""Feature is OFF"") |
|
.font(.title) |
|
} |
|
.padding() |
|
} |
|
} |
|
|