FYI: New to Swift, mainly coming from the world of Python.
I'm trying to understand dictionaries in Swift. As dictionaries are type safe in Swift I wonder why I can have nested dictionaries with different data types. I've been experimenting in XCode Playground. Example follows:
let dict = ["country": "France"]
works fine as it is [String: String] data type.
I also kind of understand the following one (is it [String: [String: String]]?):
let dict2 = [
"France": [
"capital": "Paris",
"anthem": "La Marseillaise"],
"Germany": [
"capital": "Berlin",
"anthem": "Das Lied der Deutschen"]
]
However I don't understand the following one. Why can the nested dictionary contain different data types (e.g. strings and integers)?
let dict3 = [
"France": [
"capital": "Paris",
"anthem": "La Marseillaise",
"population": 67_390_000],
"Germany": [
"capital": "Berlin",
"anthem": "Das Lied der Deutschen",
"population": 83_240_000]
]
Then I try to read the values and I can only read "the first level", i.e. dict2["France"], but not e.g. dict2["France"]["anthem"]. How come I can't read from the nested dictionary? Am I missing something fundamental here?