There are many new iOS15-specific modifiers that were added in SwiftUI. For example, we have a .focused()
modifier, which can be used like this:
TextField("Username", text: $username)
.focused($focusedField, equals: .username)
However, this code fails to compile if the app supports iOS 14 and earlier. How can I make this code to compile? Ideally, I'd like to do something like this:
TextField("Username", text: $username)
#if os(iOS, 15.0, *)
.focused($focusedField, equals: .username)
#endif
But obviously this won't work because #if os() can only specify the target OS, not the version..
Thanks!