NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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?


What version of Xcode are you using?

What OS version is your project targeting?

I cannot reproduce this issue.


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 {

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


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.


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!


Hacking with Swift is sponsored by MadMachine

SPONSORED Want to explore your Swift skill outside of the Apple world? Join the MadMachine community and start to program microcontrollers in Swift.

Get it now

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

Reply to this topic…

You need to create an account or log in to reply.

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.