UIApplication.keywindow ,must be used from main thread only warning

459 Views Asked by At

enter image description here

DispatchQueue.main.async {
}

This cause error in my Extension enter image description here

How I use it

 let topController = UIApplication.shared.topMostViewController()
1

There are 1 best solutions below

0
Arasuvel On

You can try to like below

DispatchQueue.main.async {
    let topController = UIApplication.shared.topMostViewController()
}

or alternatively you can use block. You can’t return directly from async operation.

func topMostViewController(onSuccess: (UIViewController) -> ()) {

...
}