【发布时间】:2018-03-24 07:21:51
【问题描述】:
在 Objective-C 中可以这样做:
NSString *sectionTitle = [animalSectionTitles objectAtIndex:section];
NSArray *sectionAnimals = [animals objectForKey:sectionTitle];
return [sectionAnimals count];
其中 animals 是 [String: String] 字典
但是在 Swift 3 中没有方法 objectForKey(String: ) 用于字典或任何类似的方法,或者我找不到它
【问题讨论】:
-
使用
animals[sectionTitle] -
你试过
animals[sectionTitle]吗? -
请阅读:Swift Language Guide: A Swift Tour。即使在 Objective-C 中,您也可以(并且应该)使用键和索引订阅。
标签: ios swift dictionary