@available(iOS 15.0, *) causes runtime crash on iOS 14.7 device

The following app builds, but causes a runtime crash when trying to execute on an iOS 14.7 device. Using Xcode 13b5, macOS Monterey b5, iOS 15.b6 & iOS 14.7

import SwiftUI

struct ContentView: View {
	@State private var text = "This app causes a runtime error on ios 14.7"
	@available(iOS 15.0, *)
	@FocusState var isInputActive: Bool

	var body: some View {

		if #available(iOS 15.0, *) {
			TextEditor(text: $text)
				.focused($isInputActive)
		} else {	//	ios14 or <
			TextEditor(text: $text)
		}

	}
}

Am I missing something in the above program listing?

This is such a fundamental basic requirement - to wrap @FocusState with @available(iOS 15) and then later in the code check #available(iOS 15) - that it's hard to believe that it is a bug. The more likely answer is that I'm not using these compiler directives correctly...

Any thoughts? Any help?

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)
            }
        }
    }
}

Where you able to find a solution? I get the same crash using if #available(iOS 15.0, *) { on Xcode 13.

I have the same problem :( I have a NO_CRASH_STACK + 0 crash on iOS 14.x when I use if #available(iOS 15.0, *) with @FocusState. I'm on Xcode 13.1

filled FB9808472, same here for iOS 14.5 device on Xcode 13.2

This crash happed to my app in production only built with Xcode 13.2.1 -.-

Filed FB9960857 because it still happens with Xcode 13.3, now even in Simulator

According to this answer on the Swift forums the ability to apply @available conditions to properties at all is a bug in Swift that has been fixed on the main branch, so it sounds like this code won't compile at all in future versions of Swift.

https://forums.swift.org/t/why-is-available-property-wrapper-allowed-but-stored-property-isnt/56459/2

It's actually a bug fixed on the main branch. Conditionally-available property wrappers are not allowed for the same reason as conditionally-available stored properties.

@available(iOS 15.0, *) causes runtime crash on iOS 14.7 device
 
 
Q