0

我的集合被复制到字典而不是存储为可变引用。

例如:

  var map = Dictionary<Int,Set<Int>>()
  var mySet = map[key, default: Set()]
  if mySet.count == 0 {
    // the collection doesn't exist in the dictionary so I am setting it
    // stored by value and not reference
    sectionToFeed[sectionId] = mapping
  }
  // this doesn't mutate the stored set
  mySet.insert(item)
  print(mySet)    <<<<<<<<<<<< Prints different collections
  print(map[key]) <<<<<<<<<<<<
4

0 回答 0