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

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

主站蜘蛛池模板: 大埔县| 马边| 香河县| 美姑县| 湘潭县| 辽阳市| 龙陵县| 冷水江市| 衡南县| 丹东市| 资中县| 胶南市| 木里| 宣恩县| 明水县| 皋兰县| 敖汉旗| 平利县| 青岛市| 湘乡市| 高州市| 丽江市| 临猗县| 四子王旗| 莱阳市| 丰城市| 镇康县| 岳池县| 板桥市| 临泉县| 定陶县| 加查县| 沙雅县| 晴隆县| 岳池县| 洪湖市| 理塘县| 林州市| 南木林县| 胶州市| 昌黎县|