【问题标题】:Why do the allKeys and allValues methods of NSDictionary return NSArray and not NSSet?为什么 NSDictionary 的 allKeys 和 allValues 方法返回的是 NSArray 而不是 NSSet?
【发布时间】:2014-02-15 08:39:34
【问题描述】:

当然,NSDictionary 的键是无序的,它的值也是如此。

那么,为什么NSDictionaryallKeysallValues 方法返回NSArray 而不是NSSet

【问题讨论】:

    标签: macos cocoa nsarray nsdictionary nsset


    【解决方案1】:

    一个值可以在字典中出现多次,但不能在集合中出现。所以返回一个数组会返回所有的值,而返回一个集合只会返回唯一的值。

    键当然必须是唯一的,所以我建议选择数组而不是集合是简单的一致性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-15
      • 1970-01-01
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多