Skip to content

Instantly share code, notes, and snippets.

@Clarko
Clarko / EnvironmentClosure.swift
Created July 10, 2023 01:39
Closures in the Environment
// replying to https://mastodon.world/@luckkerr/110684106839939474
import SwiftUI
struct MiscellaneousAction {
let action: () -> Void
init(_ action: @escaping () -> Void) {
self.action = action
}
@Clarko
Clarko / RemovableKeyboardShortcut.swift
Last active March 28, 2023 18:43
SwiftUI suppressible keyboard shortcuts
//
// RemovableKeyboardShortcut.swift
//
// Created by Clarko on 2/2/21.
//
// Adds an argument to dynamically remove a keyboard shortcut
//
import SwiftUI
@Clarko
Clarko / Frost.swift
Last active December 9, 2021 22:20
SwiftUI live-blur materials
// ⚠️ As of WWDC21 you can just use a SwiftUI Material
// https://developer.apple.com/documentation/swiftui/material
//
// Frost.swift
//
// Created by Clarko on 7/19/20.
//
// A SwiftUI representation of UIVisualEffectView
// and UIBlurEffect, that handles mostly like a
// SwiftUI Color view. Use it as a .background()
@Clarko
Clarko / SearchField.swift
Last active December 9, 2021 22:34
SwiftUI search field with a keyboard focus binding
// ⚠️ As of WWDC21 you can use SwiftUI .searchable
// https://developer.apple.com/documentation/swiftui/list/searchable(text:placement:)
//
// SearchField.swift
//
// Created by Clarko on 7/17/20.
//
// SwiftUI doesn't have a SearchField yet, so here's one from UIKit.
//
// The isEditing binding lets you react to keyboard focus changes,
@Clarko
Clarko / ConvenientColors.swift
Last active July 24, 2020 15:40
SwiftUI Color Extension
//
// ConvenientColors.swift
//
// Created by Clarko on 7/15/20.
//
// Color.primary and Color.secondary are great for foreground text
// that adapts in light & dark mode, but there are a lot more
// UI Element Colors in iOS and macOS:
//
// https://developer.apple.com/documentation/uikit/uicolor/ui_element_colors