2.4 KiB
PersistentCollections/PersistentDictionary
Topics
Collection Views
PersistentDictionary provides the customary dictionary views, keys and
values. These are collection types that are projections of the dictionary
itself, with elements that match only the keys or values of the dictionary,
respectively. The Keys view is notable in that it provides operations for
subtracting and intersecting the keys of two dictionaries, allowing for easy
detection of inserted and removed items between two snapshots of the same
dictionary. Because PersistentDictionary needs to invalidate indices on every
mutation, its Values view is not a MutableCollection.
Keys-swift.structValues-swift.structkeys-swift.propertyvalues-swift.property
Creating a Dictionary
init()init(_:)-7jsheinit(_:)-8ls8pinit(uniqueKeysWithValues:)-65ax0init(uniqueKeysWithValues:)-5ok18init(_:uniquingKeysWith:)-7fuzuinit(_:uniquingKeysWith:)-4jee3init(grouping:by:)-8ntzvinit(grouping:by:)-7cu86init(keys:valueGenerator:)
Inspecting a Dictionary
isEmpty-65s43count-9cdqd
Accessing Keys and Values
subscript(_:)-g0oisubscript(_:default:)index(forKey:)
Adding or Updating Keys and Values
Beyond the standard updateValue(_:forKey:) method, PersistentDictionary also
provides additional updateValue variants that take closure arguments. These
provide a more straightforward way to perform in-place mutations on dictionary
values (compared to mutating values through the corresponding subscript
operation.) PersistentDictionary also provides the standard merge and
merging operations for combining dictionary values.
updateValue(_:forKey:)updateValue(forKey:with:)updateValue(forKey:default:with:)merge(_:uniquingKeysWith:)-853bfmerge(_:uniquingKeysWith:)-19xxnmerge(_:uniquingKeysWith:)-2oshmerging(_:uniquingKeysWith:)-2a7clmerging(_:uniquingKeysWith:)-1tq3emerging(_:uniquingKeysWith:)-2kjqq
Removing Keys and Values
removeValue(forKey:)remove(at:)filter(_:)
Non-mutating Dictionary Operations
updatingValue(_:forKey:)removingValue(forKey:)
Comparing Dictionaries
==(_:_:)
Transforming a Dictionary
mapValues(_:)compactMapValues(_:)