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

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

主站蜘蛛池模板: 万宁市| 阳曲县| 乡城县| 乐亭县| 临邑县| 临朐县| 荥经县| 梅河口市| 且末县| 封开县| 马边| 东源县| 句容市| 固安县| 深州市| 乐业县| 云安县| 隆回县| 庐江县| 徐水县| 乐都县| 富顺县| 祁连县| 东阿县| 大竹县| 玛多县| 新干县| 安宁市| 吐鲁番市| 千阳县| 清涧县| 丁青县| 咸宁市| 西充县| 常德市| 湘潭市| 寿阳县| 鹤壁市| 深泽县| 涞源县| 榕江县|