15

I've got a UIKit project and I'm slowly trying to move to SwiftUI, I created a SwiftUI file and I tried to preview it but I'm getting this error:

Cannot preview in this file - Connection interrupted: send previewInstances message to agent

This is my SwiftUI File:

import SwiftUI

struct LineChart: View {
    var body: some View {
        Text("Hello, World!")
    }
}

struct LineChart_Previews: PreviewProvider {
    static var previews: some View {
        LineChart()
    }
}

Screenshot of error

I only saw one similar question on StackOverFlow but that didn't help either, is there anyway that I could fix this? Appreciate the feedback!

Şafak Gezer
  • 3,928
  • 3
  • 47
  • 49
Abdullah Ajmal
  • 367
  • 3
  • 14

3 Answers3

9

Turning off "Automatically Refresh Canvas" worked for me. (Xcode 13.2.1)

Editor>Canvas>Automatically Refresh Canvas

Şafak Gezer
  • 3,928
  • 3
  • 47
  • 49
2

Same error, seems that the automatically refresh canvas freeze the preview. Unchecking fixed the problem, but the whole sense of SwiftUI collapses without the automatic update.

1

Same error. Changing simulator worked for me in Xcode 14.2!

alamin39
  • 151
  • 1
  • 8