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 URL { | |
// https://apple.com -> https://apple.com | |
// https://애플.com -> https://xn--9e5bq00a.com | |
// https://apple.wow -> https://apple.wow | |
// apple.com -> http://apple.com | |
// 애플.com -> http://xn--9e5bq00a.com | |
// apple.wow -> nil | |
// apple -> nil | |
init?(link: String) { | |
let checkingType = NSTextCheckingResult.CheckingType.link |
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 UIApplication { | |
fileprivate static var _firstResponder: UIResponder? | |
public var firstResponder: UIResponder? { | |
Self._firstResponder = nil | |
sendAction(#selector(findFirstResponder), to: nil, from: nil, for: nil) | |
return Self._firstResponder | |
} |
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
// ModelID or TypedID 🤔 | |
public struct ModelID<Model, RawValue>: RawRepresentable { | |
public let rawValue: RawValue | |
public init(rawValue: RawValue) { | |
self.rawValue = rawValue | |
} | |
public init(_ rawValue: RawValue) { | |
self.init(rawValue: rawValue) |
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 | |
@dynamicMemberLookup | |
public struct PlainBinding<Value> { | |
private let get: () -> Value | |
private let set: (Value) -> Void | |
public init(get: @escaping () -> Value, set: @escaping (Value) -> Void) { | |
self.get = get | |
self.set = set | |
} |
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
enum Bash { | |
@discardableResult | |
static func execute(command: String, arguments: [String] = []) throws -> String { | |
let path = try execute(path: "/bin/bash", arguments: ["-lc", "which \(command)"]) | |
.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) | |
return try execute(path: path, arguments: arguments) | |
} | |
@discardableResult | |
static func execute(path: String, arguments: [String] = []) throws -> String { |
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 protocol CustomTypedNotification: TypedNotification {} | |
extension CustomTypedNotification { | |
public static var name: Notification.Name { | |
return .init(String(reflecting: self)) | |
} | |
public static func generate(from notification: Notification) -> Self { | |
let notificatonKey = TypedUserInfo.notificationUserInfoKey | |
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 | |
// Inspired by https://medium.com/developermind/using-channels-for-data-flow-in-swift-14bbdf27b471 | |
public class EventChannel<Value> { | |
private typealias SubscriptionID = ObjectIdentifier | |
private var subscriptions: [SubscriptionID: Subscription] = [:] | |
public init() {} |
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 | |
// ref.: https://github.com/apple/swift/blob/master/stdlib/public/Darwin/Foundation/NSObject.swift | |
public struct KVOChange<Value> { | |
public typealias Kind = NSKeyValueChange | |
let kind: Kind | |
let newValue: Value? |