Skip to content

Instantly share code, notes, and snippets.

View ethanhuang13's full-sized avatar

Ethan Huang ethanhuang13

View GitHub Profile
@ethanhuang13
ethanhuang13 / xcode-mcp-tools.json
Last active May 8, 2026 16:51
Xcode 26.5 mcpbridge tools/list response (generated 2026-05-09, server version 24939)
{
"tools": [
{
"description": "Retrieves current compiler diagnostics (errors, warnings, notes) for a file in the Xcode project. Returns formatted diagnostic information including severity levels and messages.",
"inputSchema": {
"properties": {
"filePath": {
"description": "The path to the file within the Xcode project organization (e.g., 'ProjectName/Sources/MyFile.swift')",
"type": "string"
},
SDK_PATH="$(xcrun --sdk iphonesimulator --show-sdk-path)" && \
xed "$SDK_PATH/System/Library/Frameworks/SwiftUICore.framework/Modules/SwiftUICore.swiftmodule/arm64-apple-ios-simulator.swiftinterface" && \
xed "$SDK_PATH/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64-apple-ios-simulator.swiftinterface"
@ethanhuang13
ethanhuang13 / VirtualKeyboard.swift
Last active July 23, 2025 01:18
MacBook Air M1 Zhuyin Keyboard written with SwiftUI ~=300 LOC, < 4hrs
//
// VirtualKeyboard.swift
// MacBook Air M1 Zhuyin Keyboard
// Written with SwiftUI ~=300 LOC, < 4hrs
// Created by Ethan Huang on 2021/1/13.
// Twitter: @ethanhuang13
import SwiftUI
struct VirtualKeyboard: View {
@ethanhuang13
ethanhuang13 / FacebookAuth.swift
Last active October 3, 2024 12:26
FacebookAuth is for iOS app developers who need to support Facebook login but don't want to use the official SDK
//
// FacebookAuth.swift
// GitHub: ethanhuang13
// Twitter: @ethanhuang13
import AuthenticationServices
import SafariServices
/*
Updated:
// iOS 17's JSONEncoder is rarely producing a different key sorting order(< 5%), which is ok for JSON itself, but will cause flaky tests.
// It wasn't happened pre-iOS 17.
// https://mastodon.social/@ethanhuang13/110904915670262949
import XCTest
final class JSONEncoderTests: XCTestCase {
func testEncode() {
struct Model: Codable {
var a: String = ""
@ViewBuilder
private func build<#name#>(_ viewStore: ViewStoreType) -> some View {
}
@ethanhuang13
ethanhuang13 / xcode-beta-slink.sh
Last active February 3, 2023 20:21
Symbolic link from Xcode.app to Xcode-beta.app (Xcode 11.2)
@ethanhuang13
ethanhuang13 / UIView+isPossiblyVisible.swift
Last active December 20, 2022 06:00
[WIP] UIView to check is visible on screen. Not perfect solution
extension UIView {
func isPossiblyVisible() -> Bool {
guard isHidden == false,
alpha > 0,
bounds != .zero,
let window = window, // In a window's view hierarchy
window.isKeyWindow, // Does not consider cases covered by another transparent window
window.hitTest(convert(center, to: nil), with: nil) != self
else { return false }
@ethanhuang13
ethanhuang13 / ErrorAlerts.swift
Created June 4, 2022 07:07
SwiftUI .alert(item:) for multiple types of Error
//
// ContentView.swift
// ErrorAlert
//
// Created by Ethan Huang on 2022/6/4.
//
import SwiftUI
enum AError: Error {
@ethanhuang13
ethanhuang13 / detect-string-language.swift
Created March 23, 2017 03:46
Detect string language with Swift
//: Playground - noun: a place where people can play
//
// The result is not guaranteed to be accurate. Typically, the function requires 200-400 characters to reliably guess the language of a string.
// Reference: [CFStringTokenizerCopyBestStringLanguage(_:_:)](https://developer.apple.com/reference/corefoundation/1542136-cfstringtokenizercopybeststringl)
//
import Foundation
extension String {
func guessLanguage() -> String {