CELLULAR
它是一个独立的模块,没有任何外部依赖。
CELLULAR 在 swift 基于的项目中共享的一些实用工具集合特性
Codable
对 KeyedDecodingContainer
有几个扩展。其中大部分都受到了 Unbox 的启发。
THE PLANET
在整个 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]
Foundation
类型
1. 允许在值赋值时推断 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
持有这些类型也可能被推断
2. 即使 surfacePressure = try container.decode(forKey: .surfacePressure)
// equals: surfacePressure = try decodeIfPresent(Double.self, forKey: key)
3. 允许集合中的实例在解码时失败
atmosphericComposition = try container.decode(forKey: .atmosphericComposition, allowInvalidElements: true) ?? []
}
}
锁定
待办事项
场景板
待办事项
要求
- iOS 11.0+ | watchOS 5.0+ | tvOS 11.0+ | macOS 10.14+ | Ubuntu 14.04+
- Swift 5.0+
安装
Swift 包管理器
一旦您设置了 Swift 包,将CELLULAR作为依赖项添加与在您的 Package.swift
的 dependencies
值中添加它一样简单。
dependencies: [
.package(url: "https://github.com/cellular/cellular-swift.git", from: "6.0.1")
]
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理工具。有关使用和安装说明,请访问他们的网站。要使用 CocoaPods 将 CELLULAR 集成到您的 Xcode 项目中,请在 Podfile 中指定它。
pod 'CELLULAR'
许可证
CELLULAR 在 MIT 许可证下发布。有关详细信息,请参阅 LICENSE。