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
#!/bin/zsh | |
# Test if the Swift compiler knows about a particular language feature. | |
# | |
# Usage: | |
# | |
# swift-has-feature [--swift SWIFT_PATH] FEATURE | |
# | |
# The exit code signals success (= the compiler knows this feature) or failure. | |
# |
#!/bin/bash | |
# Assigns a keyboard shortcut to the Export Unmodified Originals | |
# menu command in Photos.app on macOS. | |
# @ = Command | |
# ^ = Control | |
# ~ = Option | |
# $ = Shift | |
shortcut='@~^e' |
Great series of short articles introducing Apple's Metal framework.
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.
// Make sure both the string and the substring are larger than 15 UTF-8 bytes | |
// to avoid the small string optimization | |
var str = "Hello world 1 Hello world 2 Hello world 3 Hello world 4 Hello world 5 Hello world 6 Hello world 7 Hello world 8 Hello world 9" | |
let prefixToStrip = 14 | |
var substr = str.dropFirst(prefixToStrip).prefix(27) | |
let strToAppend = "+++APPENDED+++" | |
// ⚠️ It makes a difference how you mutate the Substring: | |
// - substr.append → Apparently makes a copy of the entire original string | |
// *and* even shifts the original string contents back to make room, |
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. |
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.// UserDefaults KVO observation with AsyncSequence/AsyncStream | |
// Ole Begemann, 2023-04 | |
// https://gist.github.com/ole/fc5c1f4c763d28d9ba70940512e81916 | |
import Foundation | |
extension UserDefaults { | |
func observeKey<Value>(_ key: String, valueType _: Value.Type) -> AsyncStream<Value?> { | |
var continuation: AsyncStream<Value?>.Continuation? = nil | |
let stream = AsyncStream(Value?.self) { |
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.
import CoreData | |
import Foundation | |
/// Safely copies the specified `NSPersistentStore` to a temporary file. | |
/// Useful for backups. | |
/// | |
/// - Parameter index: The index of the persistent store in the coordinator's | |
/// `persistentStores` array. Passing an index that doesn't exist will trap. | |
/// | |
/// - Returns: The URL of the backup file, wrapped in a TemporaryFile instance |