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") { ... }
Post
Replies
Boosts
Views
Activity
Here is a simple solution that works for me:
VStack (alignment: .leading) {
ZStack(alignment: .leading) {
TextEditor(text: $comment)
.frame(minHeight: 50)
Text("Comment")
.frame(width: 100, alignment: .leading)
.foregroundColor(Color(.systemGray2))
.padding(.top, -22)
.padding(.leading, 5)
.opacity(self.comment == "" ? 100 : 0)
}
}
It works rven if a user clicks/taps on the TextEditor, enters nothing, and then clicks/taps outside of the TextEdit.