Thank you, @Frameworks Engineer!
In my case your comment helped me a lot. In my app I need to differentiate an iPhone device from other devices like iPad, Mac, etc. because on iPhone I must not select by default first element in my Navigation List, but I must do this on other devices.
Initially I was checking like this:
if !UIDevice.current.model.starts(with: "iPhone") { ... }
but it showed me this warning "Main actor-isolated class property 'current' can not be referenced from a non-isolated context; this is an error in Swift 6" for such check within the (try? await ...) block. I was curious why, but now I understand, it's because UIDevice is only supported on the main thread.
So, now I'm getting the value at once in the beginning:
private let device = UIDevice.current.model
and then just check the device in other places:
if !device.starts(with: "iPhone") { ... }
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: