Tuple vs Dictionary differences

前端 未结 6 966
悲&欢浪女
悲&欢浪女 2021-01-30 10:56

Can someone please explain what the major differences there are between Tuples and Dictionaries are and when to use which in Swift?

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 11:45

    1. Dictionary is Collection Type, Tuple is Compound type.
    2. Dictionary is Key Value type, Tuple is Comma separated list of multiple types

    Dictionary:

    var dictionary = ["keyone": "value one", "keytwo": "Value Two"]

    Tuple:

    let someTuple: (Double, Double, String, (Int, Int)) = (3.14159, 2.71828, "Hello", (2, 3))
    

提交回复
热议问题