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

  • 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.

主站蜘蛛池模板: 浦县| 阳信县| 石城县| 华蓥市| 刚察县| 雅江县| 阿坝县| 烟台市| 象州县| 西充县| 古蔺县| 老河口市| 蚌埠市| 洮南市| 大方县| 平江县| 东乌珠穆沁旗| 屏山县| 康保县| 安乡县| 孟村| 西林县| 正宁县| 德化县| 西畴县| 桦南县| 剑阁县| 泽州县| 太康县| 广灵县| 洛宁县| 贵南县| 新竹县| 沙田区| 阿荣旗| 民权县| 南乐县| 射阳县| 曲周县| 浑源县| 明星|