How to access deeply nested dictionaries in Swift

后端 未结 10 935
名媛妹妹
名媛妹妹 2020-11-28 04:46

I have a pretty complex data structure in my app, which I need to manipulate. I am trying to keep track of how many types of bugs a player has in thier garden. There are te

10条回答
  •  余生分开走
    2020-11-28 05:06

    The Swift 4 default: subscript for Dictionaries makes makes updating values in nested Dictionaries much more concise.

    Get and Set a default value rather than dealing with optionals:

    var dict = [String : [String : String]]()
    dict["deep", default: [:]]["nested"] = "dictionary"
    
    print(dict)
    // ["deep": ["nested": "dictionary"]]
    

    https://swift.org/blog/dictionary-and-set-improvements/

提交回复
热议问题