KeyedDecodingContainer
上有一些扩展。 其中大部分深受 Unbox 的启发。
在整个 Codable
示例中,使用以下结构体:
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]
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)
surfacePressure = try container.decode(forKey: .surfacePressure)
// equals: surfacePressure = try decodeIfPresent(Double.self, forKey: key)
atmosphericComposition = try container.decode(forKey: .atmosphericComposition, allowInvalidElements: true) ?? []
}
}
待办事项
待办事项
一旦你设置好你的 Swift 包,将 CELLULAR 添加为依赖项就像将它添加到你的 Package.swift
的 dependencies
值中一样简单。
dependencies: [
.package(url: "https://github.com/cellular/cellular-swift.git", from: "6.0.1")
]
CocoaPods 是 Cocoa 项目的依赖管理器。 有关使用和安装说明,请访问他们的网站。 要使用 CocoaPods 将 CELLULAR 集成到你的 Xcode 项目中,请在你的 Podfile 中指定它
pod 'CELLULAR'
CELLULAR 在 MIT 许可证下发布。 查看 LICENSE 了解详细信息。