Skip to content

Instantly share code, notes, and snippets.

@swhitty
swhitty / Mutex.swift
Last active January 26, 2026 07:22
Backports the Swift 6 type Mutex<Value> to all Apple platforms that support OSAllocatedUnfairLock
// Backports the Swift 6 type Mutex<Value> to all Darwin platforms via OSAllocatedUnfairLock.
// Lightweight version of https://github.com/swhitty/swift-mutex
// Feel free to use any part of this gist.
import struct os.OSAllocatedUnfairLock
// Backports the Swift 6.0 Mutex API
@available(iOS, introduced: 16.0, deprecated: 18.0, message: "use Mutex from Synchronization module")
@available(macOS, introduced: 13.0, deprecated: 15.0, message: "use Mutex from Synchronization module")
public struct Mutex<Value: ~Copyable>: @unchecked Sendable, ~Copyable {
@Jager-yoo
Jager-yoo / forceCharWrapping.swift
Created February 3, 2024 01:07
forceCharWrapping for watchOS Text
extension String {
/// Forces the string to apply the break by character mode.
///
/// Text("This is a long text.".forceCharWrapping)
var forceCharWrapping: Self {
self.map({ String($0) }).joined(separator: "\u{200B}")
}
}
@auramagi
auramagi / WaterfallLayout.swift
Created June 27, 2022 10:52
Waterfall Layout with SwiftUI Layout protocol
import SwiftUI
struct ContentView: View {
typealias Item = (Color, CGFloat)
@State private var columnCount = 3
@State private var isWaterfall = true
@State var items: [Item] = [