Skip to content

Instantly share code, notes, and snippets.

View Kyle-Ye's full-sized avatar
💭

Kyle Kyle-Ye

💭
View GitHub Profile
@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 / 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 / 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
@Kyle-Ye
Kyle-Ye / SemanticsTestsApp.swift
Created March 12, 2025 03:28
_TestApp.setSemantics
// Ref: https://x.com/KyleSwifter/status/1899663558914572653
// The iOS 18 SwiftUI SDK has an API to change the semantic - _TestApp().setSemantics(xx).
// Remember to make it public in your SDK.
// For lower OS version, the API does not exist.
// But `_TestApp.run()` will read and set it from the `CommandLine.arguments` after `--semantics`.
@main
struct SemanticsTestsApp: App {
init() {
let app = _TestApp()
@Kyle-Ye
Kyle-Ye / UICollectionViewCell+RCTRootViewDemo.swift
Last active November 17, 2024 04:44
Workaround for UICollectionViewCell+RCTRootView
import Dispatch
import Foundation
import UIKit
extension DispatchQueue {
/// Run the action immediately if it's on the main thread, otherwise dispatch it to the main thread asynchronously.
public static func onMainThread(_ action: @escaping () -> Void) {
if Thread.isMainThread {
action()
} else {
@Kyle-Ye
Kyle-Ye / build.sh
Last active October 21, 2024 08:58
Swift 5.10 Build script
// Set up swift repo
mkdir -p ~/tmp/build/swift-project
cd ~/tmp/build/swift-project
git clone [email protected]:swiftlang/swift.git
// Update the swift-project
cd swift
utils/update-checkout --clone-with-ssh
// Check out to the 5.10 release
@Kyle-Ye
Kyle-Ye / build_xcframework.sh
Created October 13, 2024 08:13
Generate xcframework for Swift package
#!/bin/bash
# Script modified from https://docs.emergetools.com/docs/analyzing-a-spm-framework-ios
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd -P)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
PROJECT_BUILD_DIR="${PROJECT_BUILD_DIR:-"${PROJECT_ROOT}/build"}"
@Kyle-Ye
Kyle-Ye / InputHostingViewController.swift
Created August 1, 2024 13:19
SwiftUI + UIInputViewController
// Based on https://gist.github.com/liamnichols/a2e656ae93a597952b4427bcfa371185
// Add allowsSelfSizing support to support inputViewController custom height
// If you need fully dynamic height, please try https://gist.github.com/hannesoid/74ec9022021835598acf17564ce76a5a
/// `UIInputViewController` subclass that wraps a `UIHostingController` allowing you to embed SwiftUI inside `inputAccessoryViewController` and friends.
fileprivate class InputHostingViewController<Content: View>: UIInputViewController {
let hostingViewController: UIHostingController<Content>
init(rootView: Content) {
self.hostingViewController = UIHostingController(rootView: rootView)
super.init(nibName: nil, bundle: nil)