Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @start or @entry instead of @main.
Forgetting the @ symbol before main.
✗ Incorrect
The @main attribute tells Swift where the program starts. You must use @main to mark the main entry point.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the function 'start' or 'run' instead of 'main'.
Making the function non-static.
✗ Incorrect
The main function must be named 'main' to be recognized as the program's entry point.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attributes like @start or @entry.
Not marking the struct at all.
✗ Incorrect
You must mark the struct with @main to tell Swift this is the program's entry point.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @start instead of @main.
Using invalid struct names.
✗ Incorrect
Use @main to mark the struct, and the struct name can be any valid identifier like MyApp.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute names.
Naming the function something other than 'main'.
Using invalid struct names.
✗ Incorrect
The attribute is '@main', the struct name can be 'App', and the function must be named 'main'.