I have a struct
which I am initializing, with a dictionary. The values in this dictionary are of many different types: String
, Int
and Dictionary
. This embedded dictionary again, also has many different types (String
, Int
, Bool
, Array
and Dictionary
). I know, it's a mess. So, I am trying to find the correct syntax for the initializer of this struct
which takes as input this big dictionary.
I tried this, but it doesn't satisfy most of my elements.
init(dictionary: [AnyHashable: [AnyHashable: [AnyHashable: Any]]){
...
}
For instance, when trying to access a String
on the dictionary's first level, the compiler is expecting a [AnyHashable: [AnyHashable: Any]]
type object.
Is there a general way of declaring the type of this dictionary in this initializer? I want to be able to access values and either initialize variables with them or use these values as dictionaries. Is there a way to do that in Swift?
Complementary information: I'm extracting information from my FireStore DB, and this is why I have this heavily layered dictionary. FireStore documents can handle many different levels of information and I had to fill mine up for design purposes.
Thank you!