nunzio giulio caggegi
nunzio giulio caggegi

Reputation: 852

Crash on Canvas SwiftUI

i'm implementing a little app with new iOS framework SwiftUI. I'm using @EnvironmentObject to bind my data to view. All works, but the Canvas crash and not show nothing. Why?

struct CompetitionsListSwiftUIView : View {

    @EnvironmentObject var competitionsViewModel: CompetitionsViewModel

    var body: some View {
        List(self.competitionsViewModel.competitions.identified(by: \.id)) { competition in
                CompetitionCellSwiftUIView(competition: competition)
            }
    }
}

#if DEBUG
struct CompetitionsListSwiftUIView_Previews : PreviewProvider {
    static var previews: some View {
        CompetitionsListSwiftUIView()
    }
}
#endif

The error message of the Canvas is this:

Error Domain=render service Code=12 "Rendering service was interrupted" UserInfo={NSLocalizedDescription=Rendering service was interrupted}

Upvotes: 15

Views: 4146

Answers (1)

M Reza
M Reza

Reputation: 19758

Try adding your environment object to the preview:

#if DEBUG
struct CompetitionsListSwiftUIView_Previews : PreviewProvider {
    static var previews: some View {
        CompetitionsListSwiftUIView()
          .environmentObject(CompetitionsViewModel())
    }
}
#endif

Upvotes: 31

Related Questions