A collection of Swift utilities that we share across swift-based projects at CELLULAR. It is a standalone module with no external dependencies.
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]
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
discoverer = try container.decode(forKey: .discoverer) // String
hasRingSystem = try container.decode(forKey: .hasRingSystem) // Bool
numberOfMoons = try container.decode(forKey: .numberOfMoons) // Int
distanceFromSun = try container.decode(forKey: .distanceFromSun) // Float
surfacePressure = try container.decode(forKey: .surfacePressure) // Double?
atmosphericComposition = try container.decode(forKey: .atmosphericComposition, allowInvalidElements: true) ?? []
}
}
TODO
A type that represents either a success value or failure value, both of which may be of different types.
This is similar to Swift’s native Optional
type, yet, instead of nil
as error indicating, it allows none-nil failure returns with additional information.
import CELLULAR
public enum Result<Success, Failure> {
case success(Success)
case failure(Failure)
}
TODO
- iOS 9.3+ | watchOS 2.2+ | tvOS 9.2+ | macOS 10.10+ | Ubuntu 14.04+
- Swift 4.0+
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: "1.0.0")
]
CELLULAR is released under the MIT license. See LICENSE for details.