I have my SingletonRepo in my iOS app that is a in...
# multiplatform
d
I have my SingletonRepo in my iOS app that is a instance of the shared Kotlin module of my KMM app. The singleton repo:
class SingletonRepo{
static var shared = FirestoreRepo()
private init() { }
static func reset() {
//shared.closeRealm()
shared = FirestoreRepo()
}
The way that I use my repo in my Swift code:
var repo = SingletonRepo.shared
repo.myMethod()
My question is should I make the singleton class as @MainActor? While swiftching to Swift version 6 I get an error: Static property 'shared' is not concurrency-safe because it is nonisolated global shared mutable state Should I change to MainActor or Sendable?
i
What solution did you go for in the end? I used an actor in a similar situation, but I think it depends on your use case. Sharing these - helped me better understand what I needed. • Swift 6 and singletons / @Observable and data racesSwift Concurrency Playlist (quite long, but there are a few useful videos in there)