There are several extensions on KeyedDecodingContainer
.
Most of which are heavily inspired by Unbox.
Throughout the Codable
examples, the following struct is used:
import CELLULAR
public struct Planet: Codable {
public var discoverer: String
public var hasRingSystem: Bool
public var numberOfMoons: Int
public var distanceFromSun: Float // 10^6 km
public var surfacePressure: Double? // bars
public var atmosphericComposition: [String]
Foundation
types to be inferred on value assignment public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
discoverer = try container.decode(forKey: .discoverer)
// equals: discoverer = try decode(String.self, forKey: key)
hasRingSystem = try container.decode(forKey: .hasRingSystem)
// equals: hasRingSystem = try decode(Bool.self, forKey: key)
numberOfMoons = try container.decode(forKey: .numberOfMoons)
// equals: numberOfMoons = try decode(Int.self, forKey: key)
distanceFromSun = try container.decode(forKey: .distanceFromSun)
// equals: distanceFromSun = try decode(Float.self, forKey: key)
Optional
holding these types may be inferred surfacePressure = try container.decode(forKey: .surfacePressure)
// equals: surfacePressure = try decodeIfPresent(Double.self, forKey: key)
atmosphericComposition = try container.decode(forKey: .atmosphericComposition, allowInvalidElements: true) ?? []
}
}
TODO
TODO
Once you have your Swift package set up, adding CELLULAR as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/cellular/cellular-swift.git", from: "6.0.1")
]
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate CELLULAR into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'CELLULAR'
CELLULAR is released under the MIT license. See LICENSE for details.
link |
Stars: 2 |
Last commit: 4 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics