Skip to content

Instantly share code, notes, and snippets.

View huntercmeyer's full-sized avatar

Hunter Meyer huntercmeyer

View GitHub Profile
import Foundation
extension Dictionary {
func firstValue(where predicate: (Key, Value) -> Bool) -> Value? {
return self.first(where: predicate)?.value
}
}
import Foundation
extension DateFormatter {
static var full: DateFormatter {
let formatter = DateFormatter()
formatter.timeStyle = .full
formatter.dateStyle = .long
return formatter
}
}
@huntercmeyer
huntercmeyer / SheetBinding.swift
Last active October 26, 2024 02:45
A SwiftUI view modifier to present a sheet using a given item as a data source, where the sheet's content is passed a Binding to that item.
import SwiftUI
struct SheetBinding<Item: Identifiable, SheetContent: View>: ViewModifier {
@Binding var item: Item?
let onDismiss: (() -> Void)?
@ViewBuilder let sheetContent: (Binding<Item>) -> SheetContent
@ViewBuilder func body(content: Content) -> some View {
@huntercmeyer
huntercmeyer / PreviewDevice+Extension.swift
Created July 3, 2021 22:42
Type-safe iPhone Preview Device Names
import SwiftUI
extension PreviewDevice {
// MARK: iPhone
static let iPhone4s: PreviewDevice = "iPhone 4s"
static let iPhone5: PreviewDevice = "iPhone 5"
static let iPhone5s: PreviewDevice = "iPhone 5s"
static let iPhone6: PreviewDevice = "iPhone 6"
static let iPhone6s: PreviewDevice = "iPhone 6s"
static let iPhone6sPlus: PreviewDevice = "iPhone 6s Plus"