search

Home  >  Q&A  >  body text

Objective-c - Can a dictionary in OC have one key corresponding to multiple values? What does it mean if the key is different and the value is the same?

1. Can one key in the dictionary correspond to multiple values?

为情所困为情所困2826 days ago820

reply all(4)I'll reply

  • 習慣沉默

    習慣沉默2017-05-02 09:25:15

    Key cannot be repeated in a Dictionary, but Value can be repeated

    reply
    0
  • 黄舟

    黄舟2017-05-02 09:25:15

    A key can only be paired with one value, and one value can be paired with n keys

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-02 09:25:15

    Obviously the key can only correspond to one value. If the key corresponds to multiple values, when you get the key at a certain moment, the computer will not know which value you want. The principle of key-value is that the value is variable, but the key is only constant. Just like a house number, this house number indicates a certain house in this location. Value is the person living in the house. The house can change its owner, which means we assign different values ​​to value. The one value mentioned above can correspond to multiple keys is not easy to explain with this example. It can be simply understood that two keys can be equal to the same value.

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-02 09:25:15

    If the key is a person, the value can be the person's name. A person may have multiple names, but there is no second identical person in the world (key uniqueness). There are many people with the same name and surname, but People who are all different from each other (the keys are different, the values ​​can be the same, one name corresponds to n people). The individual ID is key: the name is value. This is a dictionary (key-value pair).

    reply
    0
  • Cancelreply