PreviewView icon indicating copy to clipboard operation
PreviewView copied to clipboard

Doesn't work in Xcode 14 when project targets iOS 12

Open markltownsend opened this issue 3 years ago • 1 comments

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

markltownsend avatar Sep 13 '22 13:09 markltownsend

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 image 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 🙂

theoriginalbit avatar Sep 18 '22 13:09 theoriginalbit

Fixed in 3.0.1

theoriginalbit avatar May 22 '23 09:05 theoriginalbit