2015-10-07 23 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

謝謝,就是這樣!我現在覺得有點笨。 –

相關問題