Skip to content

Instantly share code, notes, and snippets.

View daniel-beard's full-sized avatar

Daniel Beard daniel-beard

View GitHub Profile
@tonyarnold
tonyarnold / RangeReplaceableCollectionOperators.swift
Created August 25, 2020 13:29
Use this to add an operator to append items to sequences, ie: `collection += item`
extension RangeReplaceableCollection {
static func += (collection: inout Self, element: Element) {
collection.append(element)
}
static func += (collection: inout Self, element: Element?) {
if let element = element {
collection.append(element)
}
}
@amirdew
amirdew / ModifyCodable.swift
Last active March 26, 2023 06:27
Modifying private and immutable properties (let) in Codable instances
import Foundation
extension Decodable where Self: Encodable {
/// Creates a new instance and changes the value for the provided key.
///
/// - Parameters:
/// - key: The key path to the property that you want to modify.
/// Use period to separate levels and [] for indexes.
/// Examples: "id", "name.firstName", "children[2].name.firstName"
///