Post

Replies

Boosts

Views

Activity

Reply to @available(iOS 15.0, *) causes runtime crash on iOS 14.7 device
I filled out a bug report. For me it's neither working right now. As workaround you can use something like this: @available(iOS 15, *) struct FocusModifier: ViewModifier {     @FocusState var focused: Bool     @Binding var state: Bool     init(_ state: Binding<Bool>){         self._state = state     }     func body(content: Content) -> some View {         content.focused($focused, equals: true)             .onChange(of: state, perform: changeFocus)     }     private func changeFocus(_ value: Bool){         focused = value     } } @available(iOS 15, *) extension View{     func focusMe(state: Binding<Bool>) -> some View {         self.modifier(FocusModifier(state))     } } struct ContentView: View {     @State var text = ""     @available(iOS 15, *)     @State var focus = false          var body: some View{         VStack{             if #available(iOS 15, *) {                 TextField("Type here", text: $text)                     .focusMe(state: $focus)                 Button(action: {focus.toggle()}) {                     Text("Change Focus")                 }             }else{                 TextField("Type here", text: $text)             }         }     } }
Sep ’21