繁体   English   中英

Swift 如何获取字典中键的值数量?

[英]Swift How to get amount of values for key in dictionary?

在 Objective-C 中,可以这样做:

NSString *sectionTitle = [animalSectionTitles objectAtIndex:section];
NSArray *sectionAnimals = [animals objectForKey:sectionTitle];
return [sectionAnimals count];

动物是 [String: String] 字典但在 Swift 3 中没有用于字典或任何类似的方法objectForKey(String: )或者我找不到它

在 swift 你可以做到这一点

   let sectionAnimals:Array =  animals[sectionTitle]

例如

  let animals:[String:String] = ["key" : "value"]
  let sectionTitle = animalSectionTitles[0]
  let sectionAnimals = animals["key"]

如需更多帮助,您可以按照本教程教程链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM