Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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}
like image 558
nunzio giulio caggegi Avatar asked Jun 26 '19 13:06

nunzio giulio caggegi


1 Answers

Try adding your environment object to the preview:

#if DEBUG
struct CompetitionsListSwiftUIView_Previews : PreviewProvider {
    static var previews: some View {
        CompetitionsListSwiftUIView()
          .environmentObject(CompetitionsViewModel())
    }
}
#endif
like image 160
M Reza Avatar answered Nov 07 '22 04:11

M Reza