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