dictionary

var responseMessages = [200: "OK",
                        403: "Access forbidden",
                        404: "File not found",
                        500: "Internal server error"]
responseMessages.count    // 4
responseMessages[200]     // OK

var wordCount : [String:Int] = [:]     // a empty dict

// do something if key exist
if responseMessages[200] != nil {
    print("key exist")
    responseMessages[200] = "OOOOK"   // change value
}
reference:

https://developer.apple.com/documentation/swift/dictionary

你可能感兴趣的:(dictionary)