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 | |
import CoreLocation | |
// based on https://gis.stackexchange.com/a/18740 | |
extension CLLocationCoordinate2D { | |
var cartesian: CartesianCoordinate3D { .init(from: self) } | |
// Returns the coordinates of the midpoint between point a and b. | |
// Limitation: point a and b may not be diametrically opposite. |
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 Dial: View { | |
@Binding public var value: Double | |
public var minValue: Double = 0 | |
public var maxValue: Double = .greatestFiniteMagnitude | |
public var divisor: Double = 1 | |
public var stepping: Double = 1 | |
@State private var dialAngle: Angle = .zero | |
@State private var dialShadowAngle: Angle = .zero |
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 | |
@propertyWrapper | |
struct Injected<T> { | |
private let keyPath: WritableKeyPath<InjectedValues, T> | |
var wrappedValue: T { | |
get { InjectedValues[keyPath] } | |
set { InjectedValues[keyPath] = 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
import OrderedCollections | |
protocol HasCacheCost { | |
var cacheCost: Int { get } | |
} | |
extension HasCacheCost { | |
var cacheCost: Int { | |
type(of: self) == AnyObject.self ? 0 : MemoryLayout.size(ofValue: self) | |
} |
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 | |
class AutoId { | |
private init() {} | |
static func newId() -> String { | |
// Alphanumeric characters | |
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" | |
// The largest byte value that is a multiple of `char.length`. | |
let maxMultiple = Int(256 / chars.count) * chars.count |
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 | |
extension Result: Codable where Success: Codable, Failure: Codable { | |
public init(from decoder: Decoder) throws { | |
let container = try decoder.container(keyedBy: CodingKeys.self) | |
switch try container.decode(ResultType.self, forKey: .type) { | |
case .success: | |
self = .success(try container.decode(Success.self, forKey: .value)) | |
case .failure: |
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 | |
protocol Rule { | |
associatedtype Option | |
var errorMessage: String { get } | |
init(_ option: Option, error: String) | |
func validate(for value: ValidatableType) -> Bool |
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 | |
protocol AppendOnlyDatabaseProtocol { | |
var count: Int { get } | |
mutating func append(_ other: Data) | |
subscript(index: Data.Index) -> UInt8 { get } | |
subscript(bounds: Range<Data.Index>) -> Data { get } | |
} |
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 | |
typealias NewFileCallback = (fileURL: NSURL) -> Void | |
class ScreenshotDetector: NSObject, NSMetadataQueryDelegate { | |
let query = NSMetadataQuery() | |
var newFileCallback: NewFileCallback? |
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 FirebaseFirestore | |
private struct Property { | |
let label: String | |
let value: Any | |
} | |
struct FirestoreModelData { | |
let snapshot: DocumentSnapshot |
NewerOlder