Skip to content

Instantly share code, notes, and snippets.

import Foundation
extension MainActor {
/// Invoke `body`, running synchronously if possible.
///
/// This method is equivalent to `Task { @MainActor in <body> }`, except that
/// the first thread hop is elided if the caller is already on the main thread.
/// Thus if `<foo>` has no subsequent thread hops, it can run fully synchronously.
@discardableResult
public static func runAsap<Success>(
@stammy
stammy / LiquidBlobs.swift
Last active April 3, 2024 20:55
Liquid Blob effect with SwiftUI
//
// ContentView.swift
// LiquidCircles
//
// Created by Paul Stamatiou on 10/10/22.
//
import SwiftUI
struct ContentView: View {
@GreyAsteroid
GreyAsteroid / StageManagerOptions.md
Last active April 2, 2024 11:53
Stage Manager Options

defaults write com.apple.WindowManager GloballyEnabled -bool [True/False] Adjusts whether Stage Manager is enabled or not.

defaults write com.apple.WindowManager AutoHide -bool [True/False] Adjusts auto hide behavior. This option controls the "Show Recent Apps" and "Hide Recent Apps" GUI option.

defaults write com.apple.WindowManager AutoHideOverlapThreshold -int [-2147483647...2147483647] Unsure what this option does. Should be noted that when AutoHide is set to False and this option is set to -17 or lower Stage Manager behaves as if AutoHide is set to True.

defaults write com.apple.WindowManager LeftStripMaximumRowCount -int [-2147483647...2147483647]

import SwiftUI
extension CGPoint {
static func *(lhs: Self, rhs: CGFloat) -> Self {
.init(x: lhs.x * rhs, y: lhs.y * rhs)
}
}
// Idea: https://www.framer.com/showcase/project/lo2Qka8jtPXrjzZaPZdB/
import UIKit
extension UITextField {
/// Add a trailing placeholder label that tracks the text as it changes
func addTrailingPlaceholder(_ placeholder: String) {
let label = UILabel()
label.text = placeholder
label.alpha = 0.3
label.isHidden = true
let container = UIView()
// A view that can flip between its "front" and "back" side.
//
// Animation implementation based on:
// Chris Eidhof, Keyframe animations <https://gist.github.com/chriseidhof/ea0e435197f550b195bb749f4777bbf7>
import SwiftUI
// MARK: - Chris's keyframe animation design
struct Keyframe<Data: Animatable> {
@simonbs
simonbs / UserDefault.swift
Last active March 3, 2024 11:38
Property wrapper that stores values in UserDefaults and works with SwiftUI and Combine.
/**
* I needed a property wrapper that fulfilled the following four requirements:
*
* 1. Values are stored in UserDefaults.
* 2. Properties using the property wrapper can be used with SwiftUI.
* 3. The property wrapper exposes a Publisher to be used with Combine.
* 4. The publisher is only called when the value is updated and not
* when_any_ value stored in UserDefaults is updated.
*
* First I tried using SwiftUI's builtin @AppStorage property wrapper
@steipete
steipete / RandomColor.swift
Created April 6, 2021 17:20
Random Color for SwiftUI
extension Color {
/// Return a random color
static var random: Color {
return Color(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1)
)
}
}
@apptekstudios
apptekstudios / CustomPicker.swift
Last active May 28, 2021 02:35
A variation on the picker designed by Federico Zanetello in his blog post (https://fivestars.blog/swiftui/inspecting-views.html) that allows any type of content to be used
//
// CustomPicker.swift
//
// Created by T Brennan on 27/3/21.
//
import SwiftUI
struct ContentView: View {
@State private var selection: Int? = 0

This page is now depreacted!

Check out the repo instead. The Wisdom of Quinn Now with 100% more archived PDFs.

The Wisdom of Quinn

Informative DevForum posts from everyone's favorite DTS member.

(Arranged newest to oldest)