MIT License

项目介绍

Flight-School/AnyCodable 是一个托管在 GitHub 上的开源项目,主要使用 Swift 编写,采用 MIT License 许可证,目前获得 1.3k 个 Star、152 次 Fork。

仓库全名
Flight-School/AnyCodable
开源许可证
MIT License
Star 数
1.3k
Fork 数
152
未关闭 Issue
19

README 摘要

AnyCodable Type-erased wrappers for Encodable, Decodable, and Codable values. This functionality is discussed in Chapter 3 of Flight School Guide to Swift Codable. Installation Swift Package Manager Add the AnyCodable package to your target dependencies in Package.swift: Then run the swift build command to build your project. CocoaPods You can install AnyCodable via CocoaPods by adding the following line to your…

完整内容见 GitHub 原始 README 或本页 。

常见问题

AnyCodable 用什么语言开发?

主要使用 Swift 编写,采用 MIT License 许可证,目前有 1.3k 个 Star。

AnyCodable 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 AnyCodable 的源码?

可以直接克隆仓库:git clone https://github.com/Flight-School/AnyCodable.git,默认分支为 master;安装与运行步骤见仓库 README。

AnyCodable 最近还在维护吗?

仓库最近一次更新为 2024年8月7日,当前有 19 个未关闭 Issue;Star 数为 1.3k,可作为社区活跃度的参考。

简要分析

热度分
1634
价值分
842
活跃状态
归档

语言占比

Swift

README

AnyCodable

Build Status License Swift Version Cocoapods platforms Cocoapods compatible Carthage compatible

Type-erased wrappers for Encodable, Decodable, and Codable values.

This functionality is discussed in Chapter 3 of Flight School Guide to Swift Codable.

Installation

Swift Package Manager

Add the AnyCodable package to your target dependencies in Package.swift:

import PackageDescription

let package = Package(
  name: "YourProject",
  dependencies: [
    .package(
        url: "https://github.com/Flight-School/AnyCodable",
        from: "0.6.0"
    ),
  ]
)

Then run the swift build command to build your project.

CocoaPods

You can install AnyCodable via CocoaPods by adding the following line to your Podfile:

pod 'AnyCodable-FlightSchool', '~> 0.6.0'

Run the pod install command to download the library and integrate it into your Xcode project.

Note The module name for this library is “AnyCodable” — that is, to use it, you add import AnyCodable to the top of your Swift code just as you would by any other installation method. The pod is called “AnyCodable-FlightSchool” because there’s an existing pod with the name “AnyCodable”.

Carthage

To use AnyCodable in your Xcode project using Carthage, specify it in Cartfile:

github "Flight-School/AnyCodable" ~> 0.6.0

Then run the carthage update command to build the framework, and drag the built AnyCodable.framework into your Xcode project.

Usage

AnyEncodable

import AnyCodable

let dictionary: [String: AnyEncodable] = [
    "boolean": true,
    "integer": 1,
    "double": 3.141592653589793,
    "string": "string",
    "array": [1, 2, 3],
    "nested": [
        "a": "alpha",
        "b": "bravo",
        "c": "charlie"
    ],
    "null": nil
]

let encoder = JSONEncoder()
let json = try! encoder.encode(dictionary)

AnyDecodable

let json = """
{
    "boolean": true,
    "integer": 1,
    "double": 3.141592653589793,
    "string": "string",
    "array": [1, 2, 3],
    "nested": {
        "a": "alpha",
        "b": "bravo",
        "c": "charlie"
    },
    "null": null
}
""".data(using: .utf8)!

let decoder = JSONDecoder()
let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json)

AnyCodable

AnyCodable can be used to wrap values for encoding and decoding.

License

MIT

Contact

Mattt (@mattt)

评论

暂无评论