Code behind #available(iOS 16.0, *) check is called on iOS 15, causing crash on symbol not found (in ViewModifier)

Viewed 138

I made a compatibility version of .contentTransition like this:

public struct ContentTransitionNumericText: ViewModifier {
    public func body(content: Content) -> some View {
        if #available(iOS 16.0, watchOS 9.0, tvOS 16.0, macCatalyst 16.0, macOS 13.0, *) {
            content
                .contentTransition(.numericText())
        } else {
            content
        }
    }
}

public extension View {
    func contentTransitionNumericText() -> some View {
        modifier(ContentTransitionNumericText())
    }
}

However, running this on iOS 15 (with Xcode 14 beta) causes the app to crash with Symbol not found: _$s7SwiftUI17ContentTransitionVMn error. It seems that the availability check is completely ignored.

Is there a known solution to this?

EDIT: Seems like a Xcode/Swift bug, reported as FB11143522

EDIT2: The workaround from https://swiftui-lab.com/bug-os-check/ doesn't help inside ViewModifier, still crashes.

0 Answers
Related