【发布时间】:2015-02-20 06:32:52
【问题描述】:
我正在编写一个从应用程序 NSUserDefaults 中删除搜索的函数。该方法从搜索字典中删除已删除的搜索。我对这个函数的语法感到困惑。我不明白我们如何使用搜索[tags[index]] 访问搜索字典的值。要访问搜索字典的索引处的值,我们不会只说 search[index] 吗?
private var searches: Dictionary <String, String> = [:] // stores tag-query pairs
private var tags: Array<String> = [] // stores tags in user-specified order
// returns the query String for the taga at a given index
func queryForTagAtIndex(index: Int) -> String? {
return searches[tags[index]]
}
【问题讨论】:
标签: ios xcode swift dictionary