search

Home  >  Q&A  >  body text

objective-c - OC中的字典可以一个key对应多个value吗?key不同,value相同的意思是?

1.字典中的一个key可以对应多个value吗?

为情所困为情所困2758 days ago794

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