Recall & Review
beginner
What is the basic syntax to declare an actor in Swift?
Use the keyword
actor followed by the actor's name and curly braces. For example:<br>actor MyActor {
// actor code here
}Click to reveal answer
beginner
Can an actor in Swift have properties and methods?
Yes, actors can have properties and methods just like classes. These help manage state safely in concurrent code.
Click to reveal answer
intermediate
How do you mark a method inside an actor as asynchronous?
You add the
async keyword after the method's parameter list and before the return type. For example:<br>func fetchData() async -> String {
// code
}Click to reveal answer
intermediate
Why use actors instead of classes for concurrency in Swift?
Actors protect their internal state by serializing access, preventing data races in concurrent environments.
Click to reveal answer
beginner
How do you create an instance of an actor?
You create it like a class instance using the initializer:<br><pre>let myActor = MyActor()</pre>Click to reveal answer
Which keyword is used to declare an actor in Swift?
✗ Incorrect
The
actor keyword declares an actor type in Swift.What is the main benefit of using actors in Swift?
✗ Incorrect
Actors serialize access to their internal state, preventing data races in concurrent code.
How do you mark a method inside an actor as asynchronous?
✗ Incorrect
Methods that perform asynchronous work inside actors are marked with
async before the return type.How do you create an instance of an actor named
DataManager?✗ Incorrect
Actors are instantiated like classes using the initializer syntax.
Can actors in Swift have stored properties?
✗ Incorrect
Actors can have stored properties to hold their internal state.
Explain how to declare an actor in Swift and why you would use one.
Think about how actors help with safe access to data when many things happen at once.
You got /4 concepts.
Describe how asynchronous methods work inside an actor and how you declare them.
Remember that async methods let you wait for work without blocking the whole program.
You got /4 concepts.