GithubHelp home page GithubHelp logo

v-nanov / alamofire-gloss Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spxrogers/alamofire-gloss

0.0 1.0 0.0 47 KB

Gloss bindings for Alamofire

License: MIT License

Ruby 13.34% Swift 82.68% Objective-C 3.98%

alamofire-gloss's Introduction

Alamofire-Gloss

CocoaPods Carthage compatible

Gloss bindings for Alamofire for easy-peasy JSON serialization.

Installation

CocoaPods

Add to your Podfile:

pod 'Alamofire-Gloss'

Carthage

github "spxrogers/Alamofire-Gloss"

Alamofire-Gloss lists Alamofire and Gloss as explicit Carthage dependencies, so it's only necessary to list Alamofire-Gloss in your Cartfile and it will pull down all three libraries. Copy & Link generated frameworks as normal.

Usage

Define your Model

Create a Class or Struct which implements the Decodable (or Glossy) protocol.

import Foundation
import Gloss

struct Person: Decodable {

  let name: String
  let age: Int?

  init?(json: JSON) {
    guard let name: String = "name" <~~ json
      else { return nil }
    
    self.name = name
    self.age = "age" <~~ json
  }
}

API

responseObject()
responseArray()

1. Example – mapObject

Alamofire.request(personUrl).responseObject(Person.self) { (response) in
  switch response.result {
  case .success(let person):
    print("Found person: \(person)")
  case .failure(let error):
    print("Error'd: \(error)")
  }
}

2. Example – mapArray

Alamofire.request(peopleUrl).responseArray(Person.self) { (response) in
  switch response.result {
  case .success(let people):
    print("Found people: \(people)")
  case .failure(let error):
    print("Error'd: \(error)")
  }
}

Contributing

Issues and pull requests are welcome!

Author

Steven Rogers @spxrogers

Thanks ...

... to Harlan Kellaway for creating Gloss, my preferred JSON library :)

... to the Alamofire (+AFNetworking) team for paving the way of Networking in iOS.

License

Alamofire-Gloss is released under an MIT license. See LICENSE for more information.

Smile for a permissive license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.