This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
let colors = [ | |
Color.pink, | |
Color.blue, | |
Color.green, | |
Color.orange, | |
Color.purple, | |
Color.black, | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
/////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public enum Platform { | |
case iOS | |
case iOSOnMac | |
case mac | |
} | |
public func execute(if condition: Bool, _ action: () -> Void) { | |
if condition { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer