CELLULAR

CELLULAR 在 swift 项目中共享的一系列实用工具集合。
它是一个独立的模块,没有任何外部依赖。

Build Status Codecov CocoaPods Compatible Swift Version Platform

特性

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]
1. 允许在值赋值时推断 Foundation 类型
    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)
2. 甚至可以推断持有这些类型的 Optional
        surfacePressure = try container.decode(forKey: .surfacePressure)
        // equals: surfacePressure = try decodeIfPresent(Double.self, forKey: key)
3. 允许集合中的实例解码失败
        atmosphericComposition = try container.decode(forKey: .atmosphericComposition, allowInvalidElements: true) ?? []
    }
}

锁定

待办事项

Storyboard(故事板)

待办事项

要求

安装

Swift Package Manager(Swift 包管理器)

一旦你设置好你的 Swift 包,将 CELLULAR 添加为依赖项就像将它添加到你的 Package.swiftdependencies 值中一样简单。

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 了解详细信息。