I have this actor:
public actor MyActor {
private var array: [String] = []
public subscript(index: Int) -> String {
get {
array[index]
}
set {
array[index] = newValue
}
}
}
But when I try to use the subscript like this:
let myActor = MyActor()
Task {
await myActor[0] = "foo" // compilation error on this line
}
I get this compilation error:
Actor-isolated subscript 'subscript(_:)' can not be mutated from a non-isolated context
How can I use the subscript method on an actor?