官术网_书友最值得收藏!

  • Mastering Swift
  • Jon Hoffman
  • 178字
  • 2021-07-16 14:12:14

Swift collection types

A collection is a group or store of data that has a shared significance. Swift provides two native collection types for storing data. These collection types are known as arrays and dictionaries. An array will store the data in an ordered list, while a dictionary will store the data in an unordered list. In an array, we access the data by the location (index) in the array, while the data in a dictionary is accessed using a unique key that is associated with the value we want.

The data stored in a Swift collection is required to be of the same type. This means, as an example, that we are unable to store a string and an int in the same array. Since Swift does not allow us to mismatch data types in a collection, we can be certain of the data type when we retrieve data from a collection. This is another feature, which on the surface might seem like a shortcoming, but is actually a design feature that helps eliminate common programming mistakes.

主站蜘蛛池模板: 田林县| 北宁市| 乐陵市| 恭城| 拉萨市| 新源县| 高安市| 梧州市| 西乌珠穆沁旗| 尼木县| 浪卡子县| 南平市| 西峡县| 吉水县| 郑州市| 绥芬河市| 安仁县| 航空| 平南县| 乌什县| 开鲁县| 南涧| 桦川县| 潮州市| 临武县| 城口县| 沂源县| 赣州市| 西峡县| 如皋市| 明光市| 叶城县| 栾川县| 伊吾县| 永春县| 丹凤县| 东方市| 东阿县| 桃江县| 凤翔县| 洮南市|