0
0
Swiftprogramming~10 mins

Main entry point and @main attribute in 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 define the main entry point of a Swift program using the @main attribute.

Swift
@[1]
struct MyApp {
    static func main() {
        print("Hello, Swift!")
    }
}
Drag options to blanks, or click blank then click option'
Astart
Bmain
Centry
Dlaunch
Attempts:
3 left
💡 Hint
Common Mistakes
Using @start or @entry instead of @main.
Forgetting the @ symbol before main.
2fill in blank
medium

Complete the code to define the main function inside a struct marked with @main.

Swift
@main
struct App {
    static func [1]() {
        print("App started")
    }
}
Drag options to blanks, or click blank then click option'
Astart
Blaunch
Crun
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the function 'start' or 'run' instead of 'main'.
Making the function non-static.
3fill in blank
hard

Fix the error in the code by completing the missing attribute to mark the main entry point.

Swift
[1]
struct Program {
    static func main() {
        print("Running program")
    }
}
Drag options to blanks, or click blank then click option'
A@main
B@launch
C@entry
D@start
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attributes like @start or @entry.
Not marking the struct at all.
4fill in blank
hard

Fill both blanks to create a Swift program with a main entry point that prints a message.

Swift
@[1]
struct [2] {
    static func main() {
        print("Welcome!")
    }
}
Drag options to blanks, or click blank then click option'
Amain
Bstart
CMyApp
DProgram
Attempts:
3 left
💡 Hint
Common Mistakes
Using @start instead of @main.
Using invalid struct names.
5fill in blank
hard

Fill all three blanks to define a Swift program with a main entry point that prints a custom message.

Swift
@[1]
struct [2] {
    static func [3]() {
        print("Hello from Swift!")
    }
}
Drag options to blanks, or click blank then click option'
Amain
Bstart
DApp
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute names.
Naming the function something other than 'main'.
Using invalid struct names.