I'm working on an app that supports iOS 14 and up, but I would like to use some of the SwiftUI 3 property wrappers like @FocusState.
How can I work around the Stored properties cannot be marked potentially unavailable error?
Here is the simplified version of our code, it works with Xcode 13, but fails to compile with Xcode 14.
struct MyView: View { enum Field: Hashable { case username } @State private var myText: String = "" @available(iOS 15, *) @FocusState private var focusedField: Field? var body: some View { if #available(iOS 15, *) { TextEditor(text: $myText) .focused($focusedField, equals: .username) } else { TextEditor(text: $myText) } } } I cannot use a computed property with a backing storage workaround as a computed property cannot have a property wrapper.
Are there any other workarounds that I can use except for an almost identical copy of MyView?
MyViewtwice - Once for iOS14+ and once for earlier versions, drop the use of@FocusStateor drop iOS13 support. Personally, that is what I would do. A device that is stuck on ios13 is 8+ years old.@FocusStateis only iOS 15+ and we have about 10% of our customer base still on iOS 14, so not ready to drop support for that. I'm leaning towards writingMyViewtwice at this stage, but maybe somebody could think of a nicer workaround.