ios – Dictionary data does not load in SwiftUI List when list item is selected for detail view


A custom class in my project contains a Dictionary of type [String: Double] and uses SwiftData for storing and manipulating data. In a view, a SwiftUI List contains a number of objects of this class.

When I intially tap on any of the list’s items to view details of the item, the detail view doesn’t show the contents of the dictionary in the tapped item. However, when I come back to the list to tap another item, the contents of the dictionary in that item does show up. Then when I tap the initially tapped item again, the contents of the dictionary can show up this time around.

The suspected cause of this issue can be the latency in reading the data from the underlying database. While I can work around that by preloading the data of the dictionary in the view containing the list in the .onTapGesture() modifier and pass the dictionary as a parameter to the detail view for show, that would make the code look less neat and should be unnecessary. Is there a better alternative way of doing that?

I’m sorry for not providing the source here for now because that would be a whole lot of code to make this post unnecessarily long. Thank you for your understanding and help.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img