Great series of short articles introducing Apple's Metal framework.
- 2022-04-01: Day 1: Devices
- 2022-04-02: Day 2: Buffers
- 2022-04-03: Day 3: Commands
- 2022-04-04: Day 4: MTKView
- 2022-04-05: Day 5: Shaders
- 2022-04-06: Day 6: Pipelines
Great series of short articles introducing Apple's Metal framework.
| // 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 {} |
| 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. |
| #!/bin/zsh | |
| # Test if the Swift compiler knows about a particular language feature. | |
| # | |
| # Usage: | |
| # | |
| # swift-has-feature [--swift SWIFT_PATH] [--language-version LANGUAGE_VERSION] FEATURE | |
| # | |
| # The feature should be an upcoming or experimental language feature, | |
| # such as `"StrictConcurrency"` or `"ExistentialAny"`. |
| import UIKit | |
| /// A validation rule for text input. | |
| public enum TextValidationRule { | |
| /// Any input is valid, including an empty string. | |
| case noRestriction | |
| /// The input must not be empty. | |
| case nonEmpty | |
| /// The enitre input must match a regular expression. A matching substring is not enough. | |
| case regularExpression(NSRegularExpression) |
| #!/bin/bash | |
| # Assigns a keyboard shortcut to the Export Unmodified Originals | |
| # menu command in Photos.app on macOS. | |
| # @ = Command | |
| # ^ = Control | |
| # ~ = Option | |
| # $ = Shift | |
| shortcut='@~^e' |
Extract a value from the SwiftUI environment by the name of its associated EnvironmentKey (e.g. "ForegroundColorKey").
Tested only in Xcode 12.0 beta 4 in the iOS simulator. May break in other environments because it uses reflection. If SwiftUI's private type hierarchy changes, it will probably stop working.
The dynamic wallpaper in MacOS Mojave is a single 114 MB .heic file that seems to contain 16 embedded images.
It also contains the following binary plist data in its metadata under the key "Solar". It's an array of 16 items, each with four keys:
i (integer). This seems to be the image index.o (integer). This is always 1 or 0. Stephen Radford thinks it indicates dark mode (0) vs. light mode (1).a (decimal). I’m pretty sure this is the angle of the sun over the horizon. 0º = sunset/sunrise. 90º = sun directly overhead. Negative values = sun below horizon.z (decimal). This seems to be the cardinal position of the sun relative to the camera. 0º = sun is directly in front of the camera. 90º = sun is directly to the right of the camera. 180º = sun is directly behind the camera.| // swift-tools-version: 6.0 | |
| // The swift-tools-version declares the minimum version of Swift required to build this package. | |
| import PackageDescription | |
| let package = Package( | |
| name: "MyPackage", | |
| products: [ | |
| .library(name: "MyLibrary", targets: ["MyLibrary"]), | |
| ], |
A dump of the SwiftUI.framework binary for the iOS simulator (as of Xcode 12.0 beta 2) using the swift-reflection-dump tool.
Note: I used a Swift 5.3 compiler build from a few weeks ago that I had laying around. Because of ABI stability, I don't think the swift-reflection-dump version has to match the compiler version that was used to build the binary, but I'm not 100% sure.