Skip to content

Instantly share code, notes, and snippets.

View kylehughes's full-sized avatar
🐶
Updog

Kyle Hughes kylehughes

🐶
Updog
View GitHub Profile
@kylehughes
kylehughes / MockNSUbiquitousKeyValueStore.swift
Created April 29, 2024 04:52
Subclass of NSUbiquitousKeyValueStore suitable for use in unit tests.
// Copyright 2024 Kyle Hughes
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
//
@kylehughes
kylehughes / dataview_table_column-reflow.css
Created May 21, 2023 00:13
CSS for Dataview in Obsidian to give maximum width to the first column, prevent all columns from wrapping, and truncate the first column when necessary.
.table-view-table {
width: 100%;
}
.table-view-table td:not(:first-child) {
white-space: nowrap;
}
.table-view-table tr td:first-child, tr th:first-child {
overflow: hidden;
@kylehughes
kylehughes / LosslessStringConvertibleCodable.swift
Last active February 20, 2023 04:35
An example of how to implement Codable support for a type that conforms to LosslessStringConvertible.
// MARK: - Default Decodable Implementation
extension Decodable where Self: LosslessStringConvertible {
// MARK: Public Initialization
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let stringValue = try container.decode(String.self)
guard let value = Self(stringValue) else {
@kylehughes
kylehughes / StandardSizeChangeViaTraitCollectionViewController.swift
Created November 30, 2022 04:45
View controller that can override the content size category of a single child via the standard size change edit actions.
import UIKit
public final class StandardSizeChangeViaTraitCollectionViewController<Base>:
UIViewController
where
Base: UIViewController
{
public let base: Base
// MARK: Public Initialization
@kylehughes
kylehughes / MediaPicker.swift
Created September 6, 2022 21:24
MPMediaPickerController wrapped for SwiftUI
//
// MediaPicker.swift
// Music Triage
//
// Created by Kyle Hughes on 9/6/22.
//
import Foundation
import MediaPlayer
import SwiftUI
@kylehughes
kylehughes / ios-settings-deep-links.md
Last active January 11, 2022 22:20
Deep links in the iOS Settings app.
@kylehughes
kylehughes / TornRectangle.swift
Last active August 12, 2023 01:20
A rectangle shape for SwiftUI that can render any edge like a torn piece of paper.
// Copyright 2021 Kyle Hughes
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
//
@kylehughes
kylehughes / HapticFeedback.swift
Last active May 17, 2022 15:46
Convenient Swift abstractions for generating haptic feedback on iOS.
// Copyright 2021 Kyle Hughes
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
//
@kylehughes
kylehughes / Grid.swift
Last active January 2, 2022 03:13
A view modifier for SwiftUI that renders a configurable grid on top of the view. It is useful while designing in code.
// Copyright 2022 Kyle Hughes
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
//
@kylehughes
kylehughes / View+Conditional.swift
Created August 28, 2020 06:34
SwiftUI: Conditionally Configuring Views
import SwiftUI
public extension View {
// MARK: Conditionally Configuring Views
@ViewBuilder func `if`<TrueView>(
_ condition: Bool,
transform: (Self) -> TrueView
) -> some View where TrueView: View {
if condition {