2015-10-07 62 views
1

我是Swift/iOS的新手,在使用字典中的集合时遇到问题。我有以下代码:Swift 2 - 在字典中使用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

有没有人有想法?提前致谢。

回答

0

您声明attributeListslet,这意味着它是一个恒定和不可变的空字典。

+0

谢谢,就是这样!我现在觉得有点笨。 –

相关问题