[英]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.