MIT License

项目介绍

Otbivnoe/CodableAlamofire 是一个托管在 GitHub 上的开源项目,主要使用 Swift 编写,采用 MIT License 许可证,目前获得 734 个 Star、53 次 Fork。

仓库全名
Otbivnoe/CodableAlamofire
开源许可证
MIT License
Star 数
734
Fork 数
53
未关闭 Issue
2

README 摘要

Swift 4 introduces a new Codable protocol that lets you serialize and deserialize custom data types without writing any special code and without having to worry about losing your value types. 🎉 Awesome, isn't it? And this library helps you write less code! It's an extension for Alamofire that converts JSON data into Decodable object. Useful Resources: Encoding and Decoding Custom Types - Article by Apple Using JSON…

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

常见问题

CodableAlamofire 用什么语言开发?

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

CodableAlamofire 可以免费商用吗?

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

如何获取 CodableAlamofire 的源码?

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

CodableAlamofire 最近还在维护吗?

仓库最近一次更新为 2021年9月21日,当前有 2 个未关闭 Issue;Star 数为 734,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

An extension for Alamofire that converts JSON data into Decodable objects.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
841
价值分
456
活跃状态
归档

语言占比

C
Ruby
Swift

Release

README

CodableAlamofire

Build Status Swift 5.x SPM compatible Carthage Compatible Version platforms

Swift 4 introduces a new Codable protocol that lets you serialize and deserialize custom data types without writing any special code and without having to worry about losing your value types. 🎉

Awesome, isn’t it? And this library helps you write less code! It’s an extension for Alamofire that converts JSON data into Decodable object.

Useful Resources:

Usage

Let’s decode a simple json file:

{
    "result": {
        "libraries": [
            {
                "name": "Alamofire",
                "stars": 23857,
                "url": "https://github.com/Alamofire/Alamofire",
                "random_date_commit": 1489276800
            },
            {
                "name": "RxSwift",
                "stars": 9600,
                "url": "https://github.com/ReactiveX/RxSwift",
                "random_date_commit": 1494547200
            }	
        ]
    }
}

with the following Swift model:

private struct Repo: Decodable {
    let name: String
    let stars: Int
    let url: URL
    let randomDateCommit: Date
    
    private enum CodingKeys: String, CodingKey {
        case name
        case stars
        case url
        case randomDateCommit = "random_date_commit"
    }
}

There is a similar method to responseData, responseJSON - responseDecodableObject:

func responseDecodableObject<T: Decodable>(queue: DispatchQueue? = nil, keyPath: String? = nil, decoder: JSONDecoder = JSONDecoder(), completionHandler: @escaping (AFDataResponse<T>) -> Void)
  • queue - The queue on which the completion handler is dispatched.
  • keyPath - The keyPath where object decoding should be performed.
  • decoder - The decoder that performs the decoding of JSON into semantic Decodable type.
let url = URL(string: "https://raw.githubusercontent.com/otbivnoe/CodableAlamofire/master/keypathArray.json")!
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .secondsSince1970 // It is necessary for correct decoding. Timestamp -> Date.

AF.request(url).responseDecodableObject(keyPath: "result.libraries", decoder: decoder) { (response: AFDataResponse<[Repo]>) in
    let repo = response.value
    print(repo)
}

Note:

  • For array: DataResponse<[Repo]>
  • For single object: DataResponse<Repo>

Requirements

  • Swift 4+
  • Xcode 9+

Installation 🔥

CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over eighteen thousand libraries and can help you scale your projects elegantly. You can install it with the following command:

$ sudo gem install cocoapods

To integrate CodableAlamofire, simply add the following line to your Podfile:

target 'Test' do
  use_frameworks!

  pod 'CodableAlamofire'
  
end

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate CodableAlamofire into your Xcode project using Carthage, specify it in your Cartfile:

github "Otbivnoe/CodableAlamofire"

Run carthage update to build the framework and drag the built CodableAlamofire.framework into your Xcode project.

评论

暂无评论