SwiftUI @EnvironmentObject error: may be missing as an ancestor of this view

后端 未结 3 732
Happy的楠姐
Happy的楠姐 2021-02-14 19:55

my first view can get all the data from API request, then opened second view to change the API request data, it crashed.

below is the error

Fatal error:          


        
3条回答
  •  终归单人心
    2021-02-14 20:32

    The whole issue is very easy to fix just add self.networkManager @ EarthQuakeList.swift

    .sheet(isPresented: $showEditPage) { 
                                return EditPage().environmentObject(self.networkManager)
    

    I got the reason and inspired from article: https://github.com/peterfriese/Swift-EnvironmentObject-Demo

提交回复
热议问题