Just make your files as an actor like below I do:
actor SingletonWithStatic {
private init() { }
private var output = ""
static let shared = SingletonWithStatic()
func prepare(outputLine line: String) {
output += line
output += "\n"
}
func flushOutput() {
print(output)
output = ""
}
}
Or you can silent your warning by making your static variable unsafe, but make sure you use that static variable in thread safe manner.
class SingletonWithStatic {
private init() { }
private var output = ""
nonisolated(unsafe) static let shared = SingletonWithStatic()
func prepare(outputLine line: String) {
output += line
output += "\n"
}
func flushOutput() {
print(output)
output = ""
}
}
Or mark your class or struct as @MainActor