arrays - Swift 中数组、集合和字典的区别

标签 arrays swift dictionary collections set

我是 Swift Lang 的新手,看过很多教程,但还不是很清楚——我的问题是 ArraySet 之间的主要区别是什么>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/

相关文章:

c - 指向数组的指针与普通指针

swift - 保存表格 View 单元格

ios - 如何从 native 代码转到特定的 native View Controller ?

Java 如何获取特定键内的所有映射值?

c++ - 尝试访问结构中的 map 时程序卡住

PHP MySql 更新多行

c - 在C中将直接字符串分配给char数组

java - 一些消息已经简化。用-Xdiags :verbose to get full output?重新编译

ios - glUniform*fv 是否保留传递的缓冲区?

ios - 使用运行时替换字典的对象方法无效