0
0
iOS Swiftmobile~10 mins

First iOS app in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AText("Hello, world!")
BHello, world!
C'Hello, world!'
D"Hello, world!"
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.
2fill in blank
medium

Complete 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'
AUIViewController
BView
CUIView
DViewController
Attempts:
3 left
💡 Hint
Common Mistakes
Using UIKit classes like UIView or UIViewController instead of View.
Misspelling the protocol name.
3fill in blank
hard

Fix 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'
Asome View
BString
CView
DVoid
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'String' or 'Void' as the return type.
Using 'View' directly instead of 'some View'.
4fill in blank
hard

Fill 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'
A{ print("Tapped!") }
B"Tap me"
C"Tapped!"
D{ print("Hello") }
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.
5fill in blank
hard

Fill 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'
A"Hello"
B"World"
C.title
D.headline
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around text strings.
Using invalid font styles or missing the dot prefix.