Post

Replies

Boosts

Views

Activity

Bug in SwiftUI?
Hi, so I have been learning SwiftUI and writing an app. I have found out that the following code won't compile and neither Xcode shows the preview of that view. Instead Xcode will display this error message when I try to preview it: Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project Just to demonstrate this issue, all MVVM code are in a single file. Here's my code: // Model struct WatchListModel { let m_id: Int let m_ticker_symbol: String } // View struct WatchlistView: View { @ObservedObject var m_watch_list_view_model: WatchListViewModel init(watch_list_view_model: WatchListViewModel) { m_watch_list_view_model = watch_list_view_model } var body: some View { // This view is causing that issue List(m_watch_list_view_model.m_watch_list_model) { watch_list_model in Text(watch_list_model.m_ticker_symbol) }.onAppear(perform: { self.m_watch_list_view_model.populate_watch_list() }) } } extension WatchlistView { // View model class WatchListViewModel: ObservableObject { @Published var m_watch_list_model: [WatchListModel] = [] // Populate watch list func populate_watch_list() { for index in 0...10 { m_watch_list_model[index] = WatchListModel(m_id: index, m_ticker_symbol: "Foo") } } } } struct WatchlistView_Previews: PreviewProvider { static private var m_watch_list_view_model: WatchlistView.WatchListViewModel = .init() static var previews: some View { WatchlistView(watch_list_view_model: self.m_watch_list_view_model) } } I am using Xcode 12.5, though it's not the latest version. The above bug can eradicated if I remove List view and just output the contents of that array as Text view. Is there anything I can do to get around this bug?
1
0
1.6k
Aug ’21
GeometryReader's size is 0 when enclosed inside NavigationView
Hi, so I have been learning SwiftUI for a while. Recently, I have been facing this and have not been able to find a solution for it. I have noticed that when GeometryReader is enclosed inside a NavigationView then width and height of size are both 0. var body: some View { NavigationView { GeometryReader { geometryProxy in VStack { ZStack { /* Here size.width and size.height are both 0/ draw_lines_of_quadrant(screen_width: geometryProxy.size.width, screen_height: geometryProxy.size.height) } } } } } This issue can be fixed if NavigationView is enclosed inside GeoemetyReader but it won't fix my issue as I plan to load another view which has GeometryReader inside it and it must be loaded inside NavigationView Thanks
6
0
4.4k
May ’21