我的收藏集被复制到字典中,而不是存储为可变引用。
例如:
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]) <<<<<<<<<<<<