Skip to content

Instantly share code, notes, and snippets.

View jeremiasdsa's full-sized avatar

Jeremias Serafim Araujo jeremiasdsa

View GitHub Profile
@jeremiasdsa
jeremiasdsa / Dictionary.Value+RangeReplaceableCollection.swift
Created August 9, 2018 01:39 — forked from asmallteapot/Dictionary.Value+RangeReplaceableCollection.swift
Swift: Append an element to an array in a dictionary value, creating the array/value if needed
import Foundation
extension Dictionary where Value: RangeReplaceableCollection {
public mutating func append(element: Value.Iterator.Element, toValueOfKey key: Key) -> Value? {
var value: Value = self[key] ?? Value()
value.append(element)
self[key] = value
return value
}
}