ios – Accessing the energetic view controller with out utilizing @MainActor

0
28


I’ve a [String: MyViewController] cache of view controller subclasses. Inside MyViewController I’ve a property referred to as isActive:

var isActive: Bool 

That is decided by isPresented, which is my very own variable and isBeingPresented, which is one in all UIViewControllers variables.

I need to create a variable that accesses the energetic view controller like this:

var activeVc: MyViewController? {
  return cache.values.first(the place: { $0.isActive })
}

Nevertheless, this must be accessed from the primary thread in any other case it’s going to trigger a problem. I might add @MainActor to the variable to unravel this downside. Nevertheless, I might wish to keep away from having to do that. Is there a greater method round this?