Skip to content

Instantly share code, notes, and snippets.

View mrpcalcantara's full-sized avatar

Miguel Alcântara mrpcalcantara

View GitHub Profile
@mrpcalcantara
mrpcalcantara / SnapshotDiffableDataSource.swift
Last active April 5, 2023 20:24
Example on how to use the UITableViewDiffableDataSource
//
// SnapshotDiffableDataSource.swift
// testDiffableDataSource
//
// Created by Miguel Alcântara on 22/01/2020.
// Copyright © 2020 Miguel Alcântara. All rights reserved.
//
import UIKit
// Taken from https://github.com/kharrison/CodeExamples/blob/master/TableHeader/TableHeaderSwift/TableHeader/ListTableViewController.swift
// Calculate the minimum height of the header view that allows
// the text label to fit its preferred width.
let size = view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
// Taken from https://stackoverflow.com/a/55409389
public protocol RawComparable : Comparable where Self : RawRepresentable, RawValue: Comparable { }
extension RawComparable {
public static func < (lhs: Self, rhs: Self) -> Bool {
return lhs.rawValue < rhs.rawValue
}
}