All Projects → Otbivnoe → Codablealamofire

Otbivnoe / Codablealamofire

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

Programming Languages

swift
15916 projects
swift4
162 projects

Projects that are alternatives of or similar to Codablealamofire

Evreflection
Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift
Stars: ✭ 954 (+28.23%)
Mutual labels:  json, alamofire
Lychee
The most complete and powerful data-binding library and persistence infra for Kotlin 1.3, Android & Splitties Views DSL, JavaFX & TornadoFX, JSON, JDBC & SQLite, SharedPreferences.
Stars: ✭ 102 (-86.29%)
Mutual labels:  json, mapping
Kakajson
Fast conversion between JSON and model in Swift.
Stars: ✭ 867 (+16.53%)
Mutual labels:  json, mapping
Netclient Ios
Versatile HTTP Networking in Swift
Stars: ✭ 117 (-84.27%)
Mutual labels:  json, alamofire
Ws
⚠️ Deprecated - (in favour of Networking) ☁️ Elegantly connect to a JSON api. (Alamofire + Promises + JSON Parsing)
Stars: ✭ 352 (-52.69%)
Mutual labels:  json, alamofire
Tswechat
A WeChat alternative. Written in Swift 5.
Stars: ✭ 3,674 (+393.82%)
Mutual labels:  json, alamofire
Unboxedalamofire
[Deprecated] Alamofire + Unbox: the easiest way to download and decode JSON into swift objects.
Stars: ✭ 65 (-91.26%)
Mutual labels:  json, alamofire
Serpent
A protocol to serialize Swift structs and classes for encoding and decoding.
Stars: ✭ 281 (-62.23%)
Mutual labels:  json, alamofire
Daisynet
1. - Alamofire与Cache封装 , 更容易存储请求数据. 2. - 封装Alamofire下载,使用更方便
Stars: ✭ 331 (-55.51%)
Mutual labels:  json, alamofire
Arrow
🏹 Parse JSON with style
Stars: ✭ 355 (-52.28%)
Mutual labels:  json, mapping
Handyjson
A handy swift json-object serialization/deserialization library
Stars: ✭ 3,913 (+425.94%)
Mutual labels:  json, mapping
Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (-3.63%)
Mutual labels:  json
Marshal
Marshaling the typeless wild west of [String: Any]
Stars: ✭ 694 (-6.72%)
Mutual labels:  json
Mapserver
Source code of the MapServer project. Please submit pull requests to the 'main' branch.
Stars: ✭ 693 (-6.85%)
Mutual labels:  mapping
Jose Jwt
Ultimate Javascript Object Signing and Encryption (JOSE) and JSON Web Token (JWT) Implementation for .NET and .NET Core
Stars: ✭ 692 (-6.99%)
Mutual labels:  json
Typescript Generator
Generates TypeScript from Java - JSON declarations, REST service client
Stars: ✭ 729 (-2.02%)
Mutual labels:  json
Jingo
This package provides the ability to encode golang structs to a buffer as JSON very quickly.
Stars: ✭ 715 (-3.9%)
Mutual labels:  json
Pmacct
pmacct is a small set of multi-purpose passive network monitoring tools [NetFlow IPFIX sFlow libpcap BGP BMP RPKI IGP Streaming Telemetry].
Stars: ✭ 677 (-9.01%)
Mutual labels:  json
Leaflet Dvf
Leaflet Data Visualization Framework
Stars: ✭ 678 (-8.87%)
Mutual labels:  mapping
Structured Text Tools
A list of command line tools for manipulating structured text data
Stars: ✭ 6,180 (+730.65%)
Mutual labels:  json

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].