This file contains hidden or 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 WithConfigurable {} | |
public extension WithConfigurable where Self: AnyObject { | |
@discardableResult | |
func with(block: (Self) -> Void) -> Self { | |
block(self) | |
return self | |
} | |
} | |
extension NSObject: WithConfigurable {} |
This file contains hidden or 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 struct XML: CustomStringConvertible { | |
public let root: Element? | |
public init(string: String) throws { | |
root = try Parser().parse(data: Data(string.utf8)) | |
} | |
public var description: String { root?.description ?? "" } |
This file contains hidden or 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
protocol UnknownDecodable: RawRepresentable, Decodable { | |
static var unknown: Self { get } | |
} | |
extension UnknownDecodable where RawValue: Decodable { | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
self = Self.init(rawValue: try container.decode(RawValue.self)) ?? .unknown | |
} | |
} |
This file contains hidden or 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 TypedIdentifier: RawRepresentable {} | |
extension TypedIdentifier { | |
public init(_ rawValue: RawValue) { | |
self.init(rawValue: rawValue)! | |
} | |
} | |
extension TypedIdentifier where RawValue: Encodable { |
This file contains hidden or 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 UIDevice { | |
private static func sysctl(by name: String) -> String { | |
return name.withCString { | |
var size = 0 | |
sysctlbyname($0, nil, &size, nil, 0) | |
var value = [CChar](repeating: 0, count: size) | |
sysctlbyname($0, &value, &size, nil, 0) | |
return String(cString: value) | |
} |
This file contains hidden or 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 CoreVideo | |
enum CVPixelFormatType: RawRepresentable, CaseIterable { | |
typealias RawValue = OSType | |
case _1Monochrome | |
case _2Indexed | |
case _4Indexed | |
case _8Indexed | |
case _1IndexedGray_WhiteIsZero | |
case _2IndexedGray_WhiteIsZero |
This file contains hidden or 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 UIResponder { | |
struct ResponderIterator: IteratorProtocol { | |
private var responder: UIResponder? | |
init(_ responder: UIResponder) { self.responder = responder } | |
mutating func next() -> UIResponder? { | |
responder = responder?.next | |
return responder | |
} | |
} |
This file contains hidden or 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 XCTest | |
func XCTAssertEqual2(_ lhs: Any, _ rhs: Any, context: [String] = []) { | |
func displayStyle(_ value: Any) -> Mirror.DisplayStyle? { | |
return Mirror(reflecting: value).displayStyle | |
} | |
let arrL = Array(Mirror(reflecting: lhs).children).sorted { $0.label! < $1.label! } | |
let arrR = Array(Mirror(reflecting: rhs).children).sorted { $0.label! < $1.label! } | |
This file contains hidden or 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 MapKit | |
struct Polygon { | |
let coordinates: [CLLocationCoordinate2D] | |
let mapPoints: [MKMapPoint] | |
init(coordinates: [CLLocationCoordinate2D]) { | |
self.coordinates = coordinates | |
self.mapPoints = coordinates.compactMap(MKMapPointForCoordinate) | |
} |
This file contains hidden or 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 | |
private let TASK_BASIC_INFO_COUNT = mach_msg_type_number_t(MemoryLayout<task_basic_info_data_t>.size / MemoryLayout<UInt32>.size) | |
private let TASK_VM_INFO_COUNT = mach_msg_type_number_t(MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<UInt32>.size) | |
enum Process { | |
static var cpuUsage: Double { | |
var arr: thread_act_array_t? | |
var threadCount: mach_msg_type_number_t = 0 | |
NewerOlder