PreviewView
PreviewView copied to clipboard
Doesn't work in Xcode 14 when project targets iOS 12
This may be more of an issue/lockdown of the Previews starting with Xcode 14.
When trying to use the same preview code that works with Xcode 13.4.1, the Preview gives a compile error:
Compiling failed: '__designTimeString(_:fallback:)' is only available in iOS 13.0 or newer
Here is my preview code:
// MARK: - Preview
#if canImport(SwiftUI) && DEBUG
import SwiftUI
@available(iOS 13, *)
struct ContentItemHeaderView_Previews: PreviewProvider {
static let headerView: ContentItemHeaderView = {
let view = ContentItemHeaderView()
view.imageView.image = UIImage(named: "first-launch-background4")
view.titleText = "Connect With Mother Nature When You Really Want To"
view.publisherText = "Apple.com"
view.authorNameText = "Jonny Appleseed"
return view
}()
static var previews: some View {
Group {
ViewPreview(headerView)
.previewLayout(.fixed(width: 390, height: 95))
ViewPreview(headerView)
.preferredColorScheme(.dark)
.previewLayout(.fixed(width: 390, height: 95))
}
}
}
#endif
Hey there @markltownsend, thanks for the report.
I've been trying to replicate this with my tester project in Xcode 14 and I'm unable to replicate. Can you confirm the exact Xcode 14 version? Any additional details to help me replicate would be appreciated, perhaps even a simplified version of ContentItemHeaderView that can reproduce the error. Searching for the error on google and it does appear it has been cropping up for the last year or more for others, though those people are actually using SwiftUI, so this is definitely a strange one.
Unrelated but just incase you're unaware of a refactor opportunity
static var previews: some View {
Group {
ViewPreview(headerView)
.previewLayout(.fixed(width: 390, height: 95))
ViewPreview(headerView)
.preferredColorScheme(.dark)
.previewLayout(.fixed(width: 390, height: 95))
}
}
Can now actually be
static var previews: some View {
ViewPreview(headerView)
.previewLayout(.fixed(width: 390, height: 95))
}
and you can use the "Variants" button
to show light and dark at the same time, as well as a dynamic type sizes or orientation; all of which function perfectly fine with this utility 🙂
Fixed in 3.0.1