Skip to content

Instantly share code, notes, and snippets.

View ethanhuang13's full-sized avatar

Ethan Huang ethanhuang13

View GitHub Profile
@stephancasas
stephancasas / NSApplication+openSettings.swift
Last active May 30, 2025 22:51
An extension enabling global access to settings scene of a macOS SwiftUI application.
//
// NSApplication+openSettings.swift
//
// Created by Stephan Casas on 12/3/23.
//
import SwiftUI;
fileprivate let kAppMenuInternalIdentifier = "app"
fileprivate let kSettingsLocalizedStringKey = "Settings\\U2026";
@Sherlouk
Sherlouk / DebugDevice.swift
Last active April 30, 2026 00:17
Debug Profiles - Securely debugging in production
//
// DebugDevice.swift
//
// Copyright 2022 • Sidetrack Tech Limited
//
import Foundation
// This must be called on the main-thread.
var isDebugProfileInstalled: Bool {
@taskcruncher
taskcruncher / BaseStateExampleWithGenericAppState.swift
Last active August 8, 2023 17:09
BaseStateExampleWithGenericAppState.swift
//How to use BaseState struct to share state between views in TCA architecture.
// https://forums.swift.org/t/best-practice-for-sharing-data-between-many-features/37696/4
//This is a proof-of-concept only; it simply is an attempt to model how to get and set global shared state among different views in a TCA-style app.
import SwiftUI
import ComposableArchitecture
@dynamicMemberLookup
struct TCABaseState<State: Equatable>: Equatable{
@jordansinger
jordansinger / AppleLogo.swift
Created June 16, 2021 18:37
Original Apple logo in SwiftUI
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(spacing: 0) {
Color.green
Color.green
Color.green
Color.yellow
Color.orange
@steipete
steipete / RandomColor.swift
Created April 6, 2021 17:20
Random Color for SwiftUI
extension Color {
/// Return a random color
static var random: Color {
return Color(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1)
)
}
}
extension Result {
func tryMap<T>(_ transform:(Success) throws -> T) -> Result<T, Swift.Error> {
switch self {
case let .success(success):
do {
return .success(try transform(success))
} catch {
return .failure(error)
}
case let .failure(failure):
@the-yuyut
the-yuyut / AutoUpdateColor.swift
Last active January 18, 2021 06:49
Dark mode color without xcassets
import UIKit
class AutoUpdateColor: UIColor {
convenience init(lightColor: UIColor, darkColor: UIColor) {
if #available(iOS 13.0, *) {
self.init {
traitCollection in
traitCollection.userInterfaceStyle == .dark
? darkColor
: lightColor
}
extension UIHostingController {
convenience public init(rootView: Content, ignoreSafeArea: Bool) {
self.init(rootView: rootView)
if ignoreSafeArea {
disableSafeArea()
}
}
func disableSafeArea() {
#import <Foundation/Foundation.h>
// clang -o main -framework Foundation main.m
int main(int argc, const char*argv[]) {
@autoreleasepool {
NSLog(@"%@", (@42).class); // __NSCFNumber
NSLog(@"%@", (@YES).class); // __NSCFBoolean
NSLog(@"%@", @"Hello".class); // __NSCFConstantString
NSLog(@"%@", [NSString stringWithFormat:@"%d", 42].class); // NSTaggedPointerString
@GabrielMMelo
GabrielMMelo / switch-eshop.md
Last active April 3, 2026 20:41 — forked from rynkis/switch-eshop.md
Nintendo Switch eShop API