我是 Swift Lang 的新手,看过很多教程,但还不是很清楚——我的问题是 Array
、Set
和 之间的主要区别是什么>Dictionary
集合类型?
最佳答案
以下是不同类型之间的实际差异:
Arrays are effectively ordered lists and are used to store lists of information in cases where order is important.
例如,在 tableView 中显示的社交网络应用中的帖子可能存储在数组中。
Sets are different in the sense that order does not matter and these will be used in cases where order does not matter.
当您需要确保一个项目在集合中只出现一次时,集合特别有用。
Dictionaries are used to store key, value pairs and are used when you want to easily find a value using a key, just like in a dictionary.
For example, you could store a list of items and links to more information about these items in a dictionary.
希望这有帮助:)
(有关更多信息和查找 Apple 自己的定义,请在 https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html 查看 Apple 指南)
关于arrays - Swift 中数组、集合和字典的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40692077/