Updating a "safe" variable from async context

I have a variable and I have my own guarantees that updating it from a Task won't be an issue. The code is along the lines of:

var status = ""
Task {
  status = "test"
}

This errors with mutation of captured var 'status' in concurrently-executing code.

I can't remember if there is a way to mark the status variable as "safe" to update? I.e. I don't want to wrap the variable in an actor for the locking (too slow anyway) and I know that it's safe to update it from async context.

I can do:

let status = UnsafeMutablePointer<String>.allocate(capacity: 1)
status.initialize(to: "")
Task {
	status.pointee = "test"
}

But wondering if that's the way?

3 Likes