Just when I think I am finally starting to understand Swift I come across a gotcha like the following:
I have two object, a swiftui display and one of data to be displayed. Ok, sounds easy.
The data is read out of a JSON file so I have a set of arrays and dictionaries. The data is valid when read, it is definitely there, but when I go to display it, its gone. Just vanished. Wasted about a day on this so far, and I’ve seen it before, the inability to pass out of an object an array or dictionary with contents intact.
If I create an array var, and not let the system do it, contents are preserved. So, in the data object I’ll have something like this:
struct DataObject{
var item: [String:Any]
item=JSONData serialized out of memory, and may have say, 12 fields
}
In my SwiftUI module I have:
var item=dataObject.item
dataObject.item now has 0 fields.
I can allocate and initialize a dictionary in DataObject and those elements come through fine. So it seems like the stuff being serialized from JSON is being deleted out from under me.