【发布时间】:2016-01-04 12:10:30
【问题描述】:
我是 Swift/iOS 新手,在字典中使用 Set 时遇到问题。我有以下代码:
internal let attributeLists = Dictionary<String,Set<String>>()
public func getAttributeList(name: String) -> Set<String> {
if self.attributeLists[name] == nil{
self.attributeLists[name] = Set<String>()
}
return self.attributeLists[name]!
}
编译器在self.attributeLists[name] = Set<String>() 处给我一个错误
它说不能分配给这个表达式的结果。
想知道它是否与可选性有关。
当我使用self.attributeLists.updateValue(value: Set<String>(), forKey: name) 时,它会给我错误:Immutable value of type Dictionary<String,Set<String>> only has mutating members named updateValue
有人有想法吗?提前致谢。
【问题讨论】:
标签: ios dictionary set swift2