This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack { | |
FrameworkView1 { | |
Text("FrameworkView1") | |
} | |
.border(.red) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UserDefaults KVO observation with AsyncSequence/AsyncStream | |
// Ole Begemann, 2023-04 | |
// Updated for Swift 6, 2024-11 | |
// https://gist.github.com/ole/fc5c1f4c763d28d9ba70940512e81916 | |
import Foundation | |
// This is ugly, but UserDefaults is documented to be thread-safe, so this | |
// should be OK. | |
extension UserDefaults: @retroactive @unchecked Sendable {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
extension View { | |
/// Proposes a percentage of its received proposed size to `self`. | |
/// | |
/// This modifier multiplies the proposed size it receives from its parent | |
/// with the given factors for width and height. | |
/// | |
/// If the parent proposes `nil` or `.infinity` to us in any dimension, | |
/// we’ll forward these values to our child view unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MyError: Error {} | |
func fireAndForget() async { | |
await withThrowingTaskGroup(of: Void.self) { group in | |
group.addTask { | |
print("child task start") | |
print("child task throws") | |
throw MyError() | |
} | |
// Notice that we're not awaiting the child task. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Assigns a keyboard shortcut to the Export Unmodified Originals | |
# menu command in Photos.app on macOS. | |
# @ = Command | |
# ^ = Control | |
# ~ = Option | |
# $ = Shift | |
shortcut='@~^e' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
enum FinderColor: Int { | |
case noColor = 0 | |
case grey = 1 | |
case green = 2 | |
case purple = 3 | |
case blue = 4 | |
case yellow = 5 | |
case red = 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct ContainerEncoded: Encodable { | |
var date: Date = .now | |
func encode(to encoder: Encoder) throws { | |
var container = encoder.singleValueContainer() | |
try container.encode(date) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
extension View { | |
func noLargerThan(_ maxSize: CGSize) -> some View { | |
NoLargerThanLayout(maxSize: maxSize) { | |
self | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@State private var buttonTapCount: Int = 0 | |
@State private var rectTapCount: Int = 0 | |
@State private var isClippingDisabled: Bool = false | |
@State private var activateContentShape: Bool = false | |
var body: some View { | |
VStack(spacing: 40) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Item: Identifiable { | |
var id: UUID = .init() | |
var value: Int | |
} | |
let sampleItems: [Item] = (1...99).map { Item.init(value: $0) } | |
struct ContentView: View { |