Recall & Review
beginner
What is the main entry point in a Swift program?
The main entry point is where the program starts running. In Swift, this is usually the
main.swift file with top-level code or a type marked with the @main attribute.Click to reveal answer
beginner
What does the
@main attribute do in Swift?The
@main attribute tells Swift which type contains the program's entry point. Swift runs the code inside that type's static func main() method first.Click to reveal answer
intermediate
How do you define a custom main entry point using
@main in Swift?You create a struct, class, or enum with the
@main attribute and add a static func main() method. Swift runs this method when the program starts.Click to reveal answer
beginner
Can a Swift program have more than one
@main attribute?No, a Swift program can only have one
@main attribute. It marks the single entry point for the program.Click to reveal answer
intermediate
What happens if you don’t use
@main in a Swift program?If you don’t use
@main, Swift looks for a top-level main.swift file with code outside any type to start running the program.Click to reveal answer
What is the purpose of the
@main attribute in Swift?✗ Incorrect
The
@main attribute marks the type that contains the program's entry point.Which method must be implemented inside a type marked with
@main?✗ Incorrect
The type marked with
@main must implement static func main() as the entry point.Can a Swift program have multiple
@main attributes?✗ Incorrect
Swift allows only one
@main attribute to mark the single entry point.If no
@main attribute is used, how does Swift find the entry point?✗ Incorrect
Without
@main, Swift looks for a main.swift file with top-level code to start execution.Which of these can be marked with
@main in Swift?✗ Incorrect
In Swift, structs, classes, or enums can be marked with
@main to define the entry point.Explain how the
@main attribute works in Swift and how it defines the program's entry point.Think about how Swift knows where to start running your code.
You got /4 concepts.
Describe what happens if you write a Swift program without using the
@main attribute.Consider how Swift finds the start point without @main.
You got /4 concepts.