Skip to content

Instantly share code, notes, and snippets.

View mergesort's full-sized avatar
😱
Very busy with life matters, will do my best to reply as soon as I can

Joe Fabisevich mergesort

😱
Very busy with life matters, will do my best to reply as soon as I can
View GitHub Profile
@mergesort
mergesort / UIViewController+ChildViewController.swift
Created October 22, 2017 15:56
Making ChildViewControllers easier to deal with
import UIKit
extension UIViewController {
/// This function adds a `UIViewController` as a childViewController,
/// and calls the appropriate lifecycle methods.
///
/// - Parameter childViewController: The childViewController to add to the view.
func add(childViewController: UIViewController) {
self.addChildViewController(childViewController)
@mergesort
mergesort / AnimationDemo.swift
Last active December 18, 2023 02:34
A SwiftUI prototype animation for adding/removing players from a game
import SwiftUI
let colors = [
Color.pink,
Color.blue,
Color.green,
Color.orange,
Color.purple,
Color.black,
]
@mergesort
mergesort / Color+DynamicallyUpdatingUIColor.swift
Last active October 11, 2022 02:56
Color to UIColor conversion that preserves light/dark mode support for asset catalog backed colors
// Problem: Converting a Color to UIColor via the UIColor(Color) initializer does not properly respect dark/light mode.
// This becomes an issue when you have a color palette that provides different colors for dark and light mode, for example a red that's rendered darker in dark mode.
// This came up because I use asset catalogs for my apps color palettes, if you'd like to learn how to make slick SwiftUI color palettes check out: https://build.ms/2021/08/24/creating-slick-color-palette-apis
///////////////////////////
// Solution: This extension
///////////////////////////
public final class LiveActivitiesController<Model: Identifiable & Equatable & Codable, ModelActivity: ActivityAttributes & Identifiable>: ObservableObject {
var activityFromModel: (Model) -> ModelActivity
var contentStateFromModel: (Model) -> ModelActivity.ContentState
public init(activityFromModel: @escaping (Model) -> ModelActivity, contentStateFromModel: @escaping (Model) -> ModelActivity.ContentState) {
self.activityFromModel = activityFromModel
self.contentStateFromModel = contentStateFromModel
}
import Foundation
public enum Platform {
case iOS
case iOSOnMac
case mac
}
public func execute(if condition: Bool, _ action: () -> Void) {
if condition {
@mergesort
mergesort / run_in_xcode.scpt
Last active April 10, 2025 13:11
Cursor -> Xcode -> Cursor AppleScript
tell application "System Events"
if (name of processes) contains "Xcode" then
-- Check if Xcode is already the active/focused application
if (name of first application process whose frontmost is true) is not "Xcode" then
tell application "Xcode 16.2 (Beta)"
activate
delay 0.25 -- Wait for Xcode to become active
end tell
end if