Skip to content

Instantly share code, notes, and snippets.

@seanwoodward
seanwoodward / AppStorage.Key++.swift
Created March 28, 2022 15:41
Extend AppStorage property wrapper to use typed keys instead of strings
import SwiftUI
extension AppStorage {
public struct Key {
let name: String
}
}
extension AppStorage {
public init(wrappedValue: Value, _ key: AppStorage.Key, store: UserDefaults? = nil) where Value == Bool {
@seanwoodward
seanwoodward / OrdinalNumberFormatStyle.swift
Last active November 4, 2023 22:53
Quick and dirty FormatStyle for ordinal representation of a given Int
struct OrdinalNumberFormatStyle: FormatStyle {
func format(_ value: Int) -> String {
Self.ordinalFormatter.string(from: NSNumber(value: value)) ?? String(describing: value)
}
static var ordinalFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.numberStyle = .ordinal
formatter.locale = .autoupdatingCurrent
return formatter
@seanwoodward
seanwoodward / uuid.sh
Created November 3, 2023 10:15 — forked from ultim8k/uuid.sh
Generate UUID in BASH/ZSH
### Source: https://coderwall.com/p/t_sz3q/generate-uuid-at-shell-prompt
# alias uuid="python -c 'import sys,uuid; sys.stdout.write(str(uuid.uuid4()))' | pbcopy && pbpaste && echo"
alias uuid="uuidgen | tr -d '\n' | tr '[:upper:]' '[:lower:]' | pbcopy && pbpaste && echo"
@seanwoodward
seanwoodward / Tuple.swift
Last active March 19, 2024 04:36
Tuple struct using Parameter Packs to facilitate things like using a tuple as keys in dictionaries or values in sets and heaps.
#if swift(>=5.9)
import Foundation
public struct Tuple<T, each U> {
private let head: T
private let tail: (repeat (each U))
public var values: (T, repeat each U) {
@seanwoodward
seanwoodward / alignment-guides-tool.swift
Last active March 10, 2025 05:01 — forked from swiftui-lab/alignment-guides-tool.swift
A few updates to such a great example
// The SwiftUI Lab
// Website: https://swiftui-lab.com
// Article: https://swiftui-lab.com/alignment-guides
import SwiftUI
import Observation
extension EnvironmentValues {
@Entry var alignmentModel: Model = Model()
}
@seanwoodward
seanwoodward / TableColumn+contains.swift
Created July 2, 2025 15:53
StructuredQueries TableColumn contains
import StructuredQueries
extension TableColumn where Value == String {
public func contains(collate collation: Collation? = nil, all searchTerms: String...) -> any QueryExpression<Bool> {
contains(collate: collation, all: searchTerms)
}
public func contains(collate collation: Collation? = nil, all searchTerms: some Collection<String>) -> any QueryExpression<Bool> {
func makeExpression(for term: String, collation: Collation?) -> any QueryExpression<Bool> {