Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a Text view that shows "Hello, world!".
iOS Swift
import SwiftUI struct ContentView: View { var body: some View { Text([1]) } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the double quotes around the string.
Using single quotes instead of double quotes.
Passing a Text view inside another Text view.
✗ Incorrect
The Text view requires a string in double quotes to display text correctly.
2fill in blank
mediumComplete the code to make the ContentView conform to the View protocol.
iOS Swift
struct ContentView: [1] { var body: some View { Text("Welcome to my app") } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using UIKit classes like UIView or UIViewController instead of View.
Misspelling the protocol name.
✗ Incorrect
In SwiftUI, views conform to the View protocol to define their UI.
3fill in blank
hardFix the error in the code by completing the body property with a valid return type.
iOS Swift
struct ContentView: View {
var body: [1] {
Text("SwiftUI is fun!")
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'String' or 'Void' as the return type.
Using 'View' directly instead of 'some View'.
✗ Incorrect
The body property must return 'some View' to describe the view's content.
4fill in blank
hardFill both blanks to create a button that prints "Tapped!" when pressed.
iOS Swift
Button(action: [1]) { Text([2]) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the print statement as a string instead of a closure.
Using the wrong text for the button label.
✗ Incorrect
The action closure runs code on tap, and the Text shows the button label.
5fill in blank
hardFill all three blanks to create a VStack with two Text views stacked vertically.
iOS Swift
VStack {
Text([1])
Text([2])
.font([3])
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around text strings.
Using invalid font styles or missing the dot prefix.
✗ Incorrect
VStack stacks views vertically; font modifiers style the text.