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
extension StringProtocol { | |
subscript(_ offset: Int) -> String.Element { | |
if offset >= 0 { | |
self[index(startIndex, offsetBy: offset)] | |
} else { | |
self[index(endIndex, offsetBy: offset)] | |
} | |
} | |
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
//Declare extension to URLRequest: | |
extension URLRequest { | |
public var curlString: String { | |
// Logging URL requests in whole may expose sensitive data, | |
// or open up possibility for getting access to your user data, | |
// so make sure to disable this feature for production builds! | |
#if !DEBUG | |
return "" |
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
// | |
// NSApplication+openSettings.swift | |
// | |
// Created by Stephan Casas on 12/3/23. | |
// | |
import SwiftUI; | |
fileprivate let kAppMenuInternalIdentifier = "app" | |
fileprivate let kSettingsLocalizedStringKey = "Settings\\U2026"; |
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 | |
struct TaskTrigger<T: Equatable>: Equatable { | |
fileprivate enum TaskState<S: Equatable>: Equatable { | |
case inactive | |
case active(value: S, uniqueId: UUID? = nil) | |
} | |
fileprivate var state: TaskState<T> = .inactive |
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
// Inspired by: https://gist.github.com/dfrib/d7419038f7e680d3f268750d63f0dfae | |
import Foundation | |
public extension Dictionary { | |
subscript(keyPath string: Key, separator: String) -> Value? where Key == String { | |
get { return self[keyPath: string.components(separatedBy: separator)] } | |
set { self[keyPath: string.components(separatedBy: separator)] = newValue } | |
} | |
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
func getSystemUUID() -> String? { | |
let dev = IOServiceMatching("IOPlatformExpertDevice") | |
let platformExpert: io_service_t = IOServiceGetMatchingService(kIOMasterPortDefault, dev) | |
let serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, kIOPlatformUUIDKey, kCFAllocatorDefault, 0) | |
IOObjectRelease(platformExpert) | |
let ser: CFTypeRef = serialNumberAsCFString.takeUnretainedValue() | |
if let result = ser as? String { | |
return result | |
} | |
return nil |
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
extension View { | |
/// Controls the application's preferred home indicator auto-hiding when this view is shown. | |
func prefersHomeIndicatorAutoHidden(_ value: Bool) -> some View { | |
preference(key: PreferenceUIHostingController.PrefersHomeIndicatorAutoHiddenPreferenceKey.self, value: value) | |
} | |
/// Controls the application's preferred screen edges deferring system gestures when this view is shown. Default is UIRectEdgeNone. | |
func edgesDeferringSystemGestures(_ edge: UIRectEdge) -> some View { | |
preference(key: PreferenceUIHostingController.PreferredScreenEdgesDeferringSystemGesturesPreferenceKey.self, value: edge) | |
} |
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
@propertyWrapper | |
public struct Restorable<Value> { | |
public var wrappedValue: Value | |
public init(wrappedValue: Value, using undoManager: UndoManager = .init()) { | |
self.wrappedValue = wrappedValue | |
self.projectedValue = undoManager | |
} |
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
#if canImport(UIKit) | |
import UIKit | |
extension UIColor { | |
static var random: UIColor { | |
return UIColor( | |
red: .random(in: 0...1), | |
green: .random(in: 0...1), | |
blue: .random(in: 0...1) | |
) |