Skip to content

Instantly share code, notes, and snippets.

@Kyle-Ye
Kyle-Ye / CAHostingLayer.md
Last active August 6, 2026 06:28
Using CAHostingLayer in SwiftUI — access SwiftUI's SPI CALayer without Apple internal SDK

Using CAHostingLayer in SwiftUI

Background

SwiftUI provides more than just UIHostingController / _UIHostingView (iOS) and NSHostingController / NSHostingView (macOS) for embedding SwiftUI views into UIKit/AppKit.

Starting from iOS 18.0 / macOS 15.0, SwiftUI also offers CAHostingLayer<Content: View> — a CALayer subclass that can host SwiftUI content directly at the layer level. This API is currently marked as SPI (@_spi(ForUIKitOnly) / @_spi(ForAppKitOnly)) and is used internally by UIKit, AppKit, and WebKit.

Accessing CAHostingLayer without Apple Internal SDK

@Kyle-Ye
Kyle-Ye / .lldbinit-swiftui
Last active August 3, 2026 20:15
Print SwiftUI DisplayList.minimalDescription via LLDB
command script import --relative-to-command-file swiftui_displaylist_minimal_description.py
@Kyle-Ye
Kyle-Ye / kdebug_interpose.c
Created October 3, 2025 12:15
Make kdebug_is_enabled always return true
// kdebug_interpose.c
#include <stdbool.h>
#include <stdint.h>
#include <dlfcn.h>
// Forward declare the original
extern bool kdebug_is_enabled(uint32_t debugid);
// Our replacement
@Kyle-Ye
Kyle-Ye / iPhone Mirroring.md
Last active March 16, 2026 23:38
Launch iPhone Mirroring.app on macOS 15 Beta 1
@Kyle-Ye
Kyle-Ye / disable-calayersystem-swiftui-ios26.md
Created March 8, 2026 18:12
Disabling CALayerSystem Behavior in SwiftUI on iOS 26

Disabling CALayerSystem Behavior in SwiftUI on iOS 26

Starting with iOS 26, SwiftUI's UIHostingView may use CALayer-based rendering (caLayerSystem) instead of the traditional UIKit-based rendering (uikitSystem) when certain conditions are met. This can cause unexpected changes in the view hierarchy — for example, _UIGraphicsView and CGDrawingView subviews may be replaced by plain CALayer and CGDrawingLayer sublayers.

Here are two approaches to temporarily disable this behavior in your local debug environment.

Option 1: Environment Variable

Set the environment variable SWIFTUI_DISABLE_MIXED_VIEW_HIERARCHY=1 in your scheme's Run configuration (Edit Scheme → Run → Arguments → Environment Variables).

@Kyle-Ye
Kyle-Ye / ContentView.swift
Last active October 14, 2025 01:49
SwiftUI implicitRootType Playground
// Usage: ViewGraph.current.append(feature: HStackImplicitFeature())
struct HStackImplicitFeature: ViewGraphFeature {
func modifyViewInputs(inputs: inout _ViewInputs, graph: ViewGraph) {
inputs.implicitRootType = _HStackLayout.self
}
}
struct ContentView: View {
var body: some View {
ChildView1()
@Kyle-Ye
Kyle-Ye / XcodeLLM.md
Last active September 19, 2025 01:31
Enable XcodeLLM for ChinaSKU Mac on macOS 15 Beta 1

Warning

The following guide need to disable SIP to work.

Please confirm the risk of disabling the SIP by yourself.

Another solution which does not require disabling SIP is currently under investigation.

Step 0

Reboot into Recovery OS + Disable SIP

@Kyle-Ye
Kyle-Ye / DemoTests.swift
Created September 16, 2025 05:52
Unit Test SwiftUI redraws demo from OpenSwiftUI code
import Testing
import SwiftUI
@testable import Demo
typealias PlatformViewController = UIViewController
typealias PlatformWindow = UIWindow
typealias PlatformHostingController = UIHostingController
extension PlatformViewController {
// NOTE: Remember to withExtendedLifetime for window to ensure it is not deallocated duration animation or update.
@Kyle-Ye
Kyle-Ye / com.github.actions-runner.plist
Last active August 31, 2025 18:59
macOS Launch Agent for GitHub Actions Runner - Automatically runs ./run.sh in background at bootup with auto-restart and logging
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.github.actions-runner</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
@Kyle-Ye
Kyle-Ye / swift_6.1_linux_toolchain_patch.sh
Created May 11, 2025 09:36
A patch to workaround Swift 6.1 include CoreFoundation issue on Linux
#!/bin/bash
# A temporay workaround for https://github.com/swiftlang/swift-corelibs-foundation/issues/5211
set -e
# Find the path to swift binary
SWIFT_PATH=$(which swift)
echo "Swift binary found at: $SWIFT_PATH"
# Extract the toolchain path from swift binary path
# Remove /usr/bin/swift from the path to get the toolchain root