0
0
Swiftprogramming~5 mins

Nonisolated methods in Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the nonisolated keyword mean in Swift concurrency?
It means the method can be called without switching to the actor's isolated context. The method runs without actor isolation, allowing safe access to non-isolated data.
Click to reveal answer
intermediate
Why use nonisolated methods inside an actor?
To allow some methods to run without waiting for actor isolation, improving performance for read-only or stateless operations that don't need exclusive access.
Click to reveal answer
intermediate
Can a nonisolated method access actor-isolated state directly?
No. Nonisolated methods cannot access actor-isolated properties or methods directly because they run outside the actor's isolation.
Click to reveal answer
beginner
Example: How to declare a nonisolated method in an actor?
Inside an actor, write nonisolated func methodName() { ... } to mark the method as nonisolated.
Click to reveal answer
beginner
What happens if you call a normal actor method from outside the actor?
The call is asynchronous and requires awaiting because the method runs in the actor's isolated context to ensure safe access.
Click to reveal answer
What is the main purpose of marking a method as nonisolated in a Swift actor?
ATo make the method asynchronous
BTo prevent the method from being called
CTo allow the method to run without actor isolation
DTo make the method private
Can a nonisolated method access actor-isolated properties directly?
AYes, always
BOnly if called from inside the actor
COnly if marked async
DNo, never
Which keyword do you use to mark a method as running outside actor isolation?
Anonisolated
Bisolated
Casync
Dprivate
What happens when you call a normal actor method from outside the actor?
AIt runs synchronously
BIt requires awaiting because it runs asynchronously
CIt throws an error
DIt runs without isolation
Which of these is a good use case for a nonisolated method?
APerforming stateless calculations
BReading actor-isolated properties
CModifying actor state
DCalling other isolated methods
Explain what a nonisolated method is in Swift actors and why you might use it.
Think about how actor isolation controls access and when you might want to bypass it safely.
You got /3 concepts.
    Describe the difference between calling a normal actor method and a nonisolated method from outside the actor.
    Consider how actor isolation affects method calls and concurrency.
    You got /3 concepts.