SwiftUI preview: error: '__designTimeInteger(_:fallback:)' is only available in iOS 13.0 or newer

Hi, I'm using SwiftUI previews with the UIViewRepresentable protocol in order to preview UIViews. The project requires iOS 12 but I wrap the SwiftUI preview code in #if canImport(SwiftUI) && DEBUG ... #endif, and the PreviewProvider struct is marked with @available(iOS 13, *). This used to work flawlessly in Xcode 13.

But now I have a weird compilation error when running the preview:

Compiling failed: '__designTimeInteger(_:fallback:)' is only available in iOS 13.0 or newer

The relevant part of the error report is this one:

/path/to/file.swift:52:52: error: '__designTimeInteger(_:fallback:)' is only available in iOS 13.0 or newer

    .init(width: UIView.noIntrinsicMetric, height: __designTimeInteger("#7274.[4].[5].property.[0].[0].arg[1].value", fallback: 44))

Line 52 only contains the initialization of a CGSize instance:

override public var intrinsicContentSize: CGSize {
  .init(width: UIView.noIntrinsicMetric, height: 44)
}

Any idea what's going on here? The project compiles without issues and the selected simulator is iPhone 8 running iOS 16.

I have same issue

Ran into this issue today. I was able to get around it by setting my deployment target to iOS 13.0. Since my project targets an earlier version, I set the deployment target to iOS 13.0 for Debug only.

I'm having the same issue. I have a project targeting iOS 12 and previews worked great with Xcode 13 but are completely broken with Xcode 14+. It seems to be related to how the compiler handles primitives. I created a barebones project targeting iOS 12 and the previews work fine if there are no primitive values in the file, but as soon as there is a primitive being used it breaks, but using a collection of primitives works fine.

Strangely if I move the preview code to a separate file it works fine, so this definitely seems like an Xcode 14 bug or the compiler has been tightened up and we can't do the #if DEBUG @available(iOS 13, *) workaround anymore.

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // UIView works
        let view = UIView()

        // An array of strings works
        let strArray = [String]()

        // Using a string breaks
        let str = "hello world!"

        // Using a CGFloat breaks
        let num: CGFloat = 1337

        // Using a Bool breaks
        let bool = false

    }
}

#if DEBUG

import SwiftUI

@available(iOS 13, *)
struct Test_Previews: PreviewProvider {

    static var previews: some View {
        Group {
            Color.orange.frame(height: 100)
        }
    }
}

#endif

Same here. What worked for me was to remove the preview part from the code, save. Added it back and it all worked.

SwiftUI preview: error: '__designTimeInteger(_:fallback:)' is only available in iOS 13.0 or newer
 
 
Q