Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.7 kB · 60 lines
Swift
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061//// StringCodingKey.swift// URLQueryItemCoder//// Created by Kyle Hughes on 1/15/23.//
/// A basic coding key implementation for stringly-keyed collections.internal struct StringCodingKey { /// The value to use in an integer-indexed collection (e.g. an int-keyed dictionary). internal let intValue: Int? /// The string to use in a named collection (e.g. a string-keyed dictionary). internal let stringValue: String // MARK: Private Initialization private init(intValue: Int?, stringValue: String) { self.intValue = intValue self.stringValue = stringValue }}
// MARK: - CodingKey Extension
extension StringCodingKey: CodingKey { // MARK: Internal Initialization /// Creates a new instance from the specified integer. /// /// - Parameter intValue: The integer value of the desired key. internal init(intValue: Int) { self.intValue = intValue stringValue = String(intValue) } /// Creates a new instance from the given string. /// /// - Parameter stringValue: The string value of the desired key. internal init(stringValue: String) { self.stringValue = stringValue intValue = nil }}
// MARK: - ExpressibleByStringLiteral Extension
extension StringCodingKey: ExpressibleByStringLiteral { // MARK: Internal Initialization /// Creates an instance initialized to the given string value. /// /// - Parameter stringLiteral: The value of the new instance. @inlinable internal init(stringLiteral value: String) { self.init(stringValue: value) }}