Skip to content

Instantly share code, notes, and snippets.

View SwiftUIIfModifier.swift
extension View {
@ViewBuilder
func `if`<Content: View>(_ conditional: Bool, @ViewBuilder content: (Self) -> Content) -> some View {
if conditional {
content(self)
}
else {
self
}
}
View FB9750689.md

When creating and using a custom ButtonStyle for a SwiftUI button that changes its appearance based on the value of the configuration.isPressed property, that property sometimes get stuck with a "true" value, leaving the button to appear in its pressed state even when it is not being pressed. It stays stuck this way until the button is clicked again.

A sample project is attached. It's also in a public repo at https://github.com/siracusa/SwiftUIButtonIsPressedStateBug

To reproduce the bug:

  1. Build and launch the sample project. A window should appear showing a large button view with a green background and some white text that says "Hello".

  2. Click button view a few times and confirm that background color turns blue on mouse-down and switches back to green on mouse-up.

@siracusa
siracusa / Pro Display XDR at 120Hz bandwidth calculation.md
Last active Aug 10, 2022
Pro Display XDR at 120Hz bandwidth calculations
View Pro Display XDR at 120Hz bandwidth calculation.md

From Jonathan Dietz, Jr.:

Almost all new displays employ VESA Coordinated Video Timings using Reduced Blanking Timing Version 2 (CVT-RBv2) which adds a small amount of overhead to the video signal. This overhead includes 80 additional horizontal pixels and enough additional lines to meet the 460 µs minimum vertical blanking interval requirement. You can download an Excel spreadsheet from VESA that will do all the calculations for you, but the math is pretty simple:

460 / ((1000000 / [refresh rate in Hz] - 460) / [vertical resolution])

To get an integer number of lines, you round this result down and add 1. So for Pro Display XDR resolution at 120 Hz that would work out to:

460 / (1000000 / 120 - 460) / 3384) = 197.710 = 198 additional lines

View Safari Customize Toolbar Sample.txt
Sampling process 2517 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling Safari (pid 2517) every 1 millisecond
Process: Safari [2517]
Path: /Applications/Safari.app/Contents/MacOS/Safari
Load Address: 0x10a637000
Identifier: com.apple.Safari
Version: 15.0 (15612.1.29.41.4)
Build Info: Safari-7612001029041004~7
Code Type: X86-64
View Safari 15 Customize Toolbar Crash Log.txt
Process: Safari [2517]
Path: /Applications/Safari.app/Contents/MacOS/Safari
Identifier: com.apple.Safari
Version: 15.0 (15612.1.29.41.4)
Build Info: Safari-7612001029041004~7 (612A69a)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Safari [2517]
User ID: 67152294
View gist:9c82d6fc2fff1e135b2f01e1aacc9f9b
579 => Blessed System File is /System/Volumes/Preboot/B24F40F6-A709-475D-8FE9-0BC32E6BA240/System/Library/CoreServices/boot.efi
366 => Blessed System Folder is /System/Volumes/Preboot/B24F40F6-A709-475D-8FE9-0BC32E6BA240/System/Library/CoreServices
The blessed volume in this APFS container is "/".
The blessed APFS snapshot for this volume is "3E14543D-BE61-487B-B49A-2AF55563C403".
View nested_string_escapes.pl
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
# Increase this number as your sanity allows
use constant PAREN_DEPTH => 5;
View gist:f2e9cc3d19acff5f1f0afeb9033bffa0
Jun 14 12:18:00 … osinstallersetupd[8829]: seedingInfoDict ->
Jun 14 12:18:00 … osinstallersetupd[8829]: result : Success
Jun 14 12:18:00 … osinstallersetupd[8829]: seedProgramSource : Xattr
Jun 14 12:18:00 … osinstallersetupd[8829]: seedProgram : DeveloperSeed
Jun 14 12:18:00 … osinstallersetupd[8829]: catalogURLString : https://swscan.apple.com/content/catalogs/others/index-10.15seed-10.15-10.14-10.13-10.12-10.11-10.10-10.9-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog
Jun 14 12:18:00 … osinstallersetupd[8829]: fileName : /Applications/Install macOS 10.15 Beta.app
Jun 14 12:18:00 … osinstallersetupd[8829]: error : No error
Jun 14 12:18:00 … osinstallersetupd[8829]: Build phase is Beta. Target Seed Program will be set to DeveloperSeed (Source:Xattr). Recorded into the mutable product.
Jun 14 12:18:00 … osishelperd[8843]: +[IA_IASBlessUtilities setEFIBackupBootDevice]: Booted volume: disk1s1
View SILDemoOptimized.sil
sil_stage canonical
import Builtin
import Swift
import SwiftShims
// SILDemo.identity <A>(A) -> A
sil @_TF7SILDemo8identityU__FQ_Q_ : $@thin <T> (@out T, @in T) -> () {
bb0(%0 : $*T, %1 : $*T):
copy_addr [take] %1 to [initialization] %0 : $*T // id: %2
View SILDemo.sil
sil_stage canonical
import Builtin
import Swift
import SwiftShims
// SILDemo.identity <A>(A) -> A
sil @_TF7SILDemo8identityU__FQ_Q_ : $@thin <T> (@out T, @in T) -> () {
bb0(%0 : $*T, %1 : $*T):
debug_value_addr %1 : $*T // let x // id: %2