UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 19 HWS+ Advanced Solution @FocusState caused failure in Preview "Cannot preview in this file - Converter crashed"

Forums > 100 Days of SwiftUI

When I open Paul's advanced solution in Xcode, the preview window displays "Cannot preview in this file - Converter crashed". I've narrowed the source of the problem down to

    @FocusState private var inputIsFocused: Bool

When I comment out this line (and all the lines that are dependent on it) the preview error goes away.

When the line, and the dependents, are live, the project builds and runs just fine, but causes the error in Preview.

Anybody got any ideas on how to fix the problem?

2      

What version of Xcode are you using?

What OS version is your project targeting?

I cannot reproduce this issue.

2      

Thanks for taking an interest.

Xcode v13.2.1 Target iPhone iPad 15.0

I can start with a new SwiftUI project, add the @FocusState and get the error.

Once I narrowed down the source of the problem, I did some additional web searching and found a workaround:

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ZStack {
            ContentView()
        }
    }
}

Adding the ZStack made the error in the canvas go away.

3      

Had similar problem, but on Day 18. XCode v13.2.1 target iPhone iPad 15.2 Thanks for the solution! Wish I understood why this fixed it.

Afterwards, wound up removing ContentView_Previews struct entirely, hiding canvas, and using only simulator.

2      

I had the same issue, I figured that something needed to be added to the preview to make it work. That generally has been the issue for me when previews crash.

Thanks for the solution!

1      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.