Skip to content

Instantly share code, notes, and snippets.

View qmchenry's full-sized avatar

Quinn McHenry qmchenry

View GitHub Profile
@qmchenry
qmchenry / PreviewHelpers.swift
Created August 5, 2021 17:00
Decodable instantiation from an asset catalog Data Set to help with SwiftUI Previews
import UIKit
extension NSDataAsset {
/// Load a data asset from a catalog and try decoding it to a specific Decodable type
/// - Returns: An optional instance of type T decoded from the named data asset
/// Usage: `NSDataAsset.decode(DocodableThing.self, asset: "my thing")`
public static func decode<T>(_ type: T.Type, asset name: String) -> T? where T: Decodable {
guard let asset = Self(name: name) else { return nil }
return try? JSONDecoder().decode(T.self, from: asset.data)
}
@qmchenry
qmchenry / DumpView.swift
Last active February 22, 2022 16:57
dump() example
// DumpExample
// This SwiftUI View explores use of the dump() function for manipulating the debugging display
// of large, structured data.
//
// Created by Quinn McHenry on 2/17/22.
import SwiftUI
struct ContentView: View {