Complete the code to declare a nonisolated method in an actor.
actor Counter {
nonisolated func [1]() -> String {
return "Hello from nonisolated method"
}
}The method greet is declared as nonisolated to allow calling it without actor isolation.
Complete the code to mark the method as nonisolated in the actor.
actor Logger {
[1] func log(message: String) {
print(message)
}
}The nonisolated keyword allows the log method to be called without actor isolation.
Fix the error by adding the correct keyword to the method to make it nonisolated.
actor DataStore {
func fetch() -> String {
return "Data"
}
[1] func info() -> String {
return "Info"
}
}Adding nonisolated to info allows it to be called without actor isolation.
Fill both blanks to create a nonisolated static method inside an actor.
actor Service {
[1] [2] func status() -> String {
return "Running"
}
}The method is both nonisolated and static, so it can be called without actor isolation and without an instance.
Fill the blank to define a nonisolated async method inside an actor.
actor Network {
[1] func fetchData() async -> String {
return "Data fetched"
}
}async before func (invalid syntax; async belongs in the signature after ()).nonisolated or using isolated.The method is marked nonisolated before func and async after the parameters in the signature.