07-18-2023, 10:12 PM
I'm trying to render some views in background thread to not affect the main thread. That was never a problem before Xcode 9.
DispatchQueue.global(qos: .background).async {
let customView = UIView(frame: .zero)
DispatchQueue.main.async {
self.view.addSubview(customView)
}
}
> UIView.init(frame:) must be used from main thread only
This error occurs in the second line.
**Update**
The Apple `UIView` Documentation actually says in the *Threading Considerations* section:
> Manipulations to your application’s user interface must occur on the main thread. Thus, you should always call the methods of the UIView class from code running in the main thread of your application. **The only time this may not be strictly necessary is when creating the view object itself, but all other manipulations should occur on the main thread.**
DispatchQueue.global(qos: .background).async {
let customView = UIView(frame: .zero)
DispatchQueue.main.async {
self.view.addSubview(customView)
}
}
> UIView.init(frame:) must be used from main thread only
This error occurs in the second line.
**Update**
The Apple `UIView` Documentation actually says in the *Threading Considerations* section:
> Manipulations to your application’s user interface must occur on the main thread. Thus, you should always call the methods of the UIView class from code running in the main thread of your application. **The only time this may not be strictly necessary is when creating the view object itself, but all other manipulations should occur on the main thread.**