Skip to content

Instantly share code, notes, and snippets.

Michael Waterfall mwaterfall

Block or report user

Report or block mwaterfall

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Changeable.swift
public protocol Changeable {}
extension Changeable {
/// Calls the `changes` closure passing the receiver value as an `inout` parameter. The final value of the argument
/// after the `changes` closure returns is then returned from this method. Benefits to using this function come
/// when used against value types.
/// Example:
/// extension UIEdgeInsets: Changeable {}
View Material+UnknownCaseRepresentable.swift
enum Material: String {
case wood, metal, glass, other
extension Material: Codable {}
extension Material: UnknownCaseRepresentable {
static let unknownCase: Material = .other
View UnknownCaseRepresentable.swift
protocol UnknownCaseRepresentable: RawRepresentable, CaseIterable {
static var unknownCase: Self { get }
extension UnknownCaseRepresentable where Self.RawValue: Equatable {
init(rawValue: RawValue) {
let value = Self.allCases.first(where: { $0.rawValue == rawValue })
self = value ?? Self.unknownCase
View Material+Decoding2.swift
extension Material {
init(from decoder: Decoder) throws {
self = try Material(from: decoder, default: .other)
View RawRepresentable+Decodable.swift
extension RawRepresentable where RawValue: Decodable {
init(from decoder: Decoder, default: Self) throws {
let container = try decoder.singleValueContainer()
let rawValue = try container.decode(RawValue.self)
self = Self(rawValue: rawValue) ?? `default`
View Material+Decoding.swift
extension Material {
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let rawMaterial = try container.decode(String.self)
self = Material(rawValue: rawMaterial) ?? .other
View Material.swift
enum Material: String, Codable {
case wood, metal, glass, other
View ImageDescriptorUsage.swift
.productImage(with: URL(string: "http://my-image-url")!),
loading: .loading,
failure: .failure
View ImageDescriptors.swift
extension ImageDescriptor where ImageReference == UIImage {
static let logo = ImageDescriptor<UIImage>(
imageReference: UIImage(named: "logo")!.withRenderingMode(.alwaysTemplate),
properties: UIImageView.Properties(
contentMode: .center,
backgroundColor: .white,
tintColor: .lightGray,
accessibilityIdentifier: "logoImage"
View UIImageView+ImageDescriptor.swift
extension UIImageView {
func apply(_ imageDescriptor: ImageDescriptor<UIImage>) {
accessibilityIdentifier =
backgroundColor =
contentMode =
tintColor =
image = imageDescriptor.imageReference
You can’t perform that action at this time.