Alamofire-Gloss CocoaPods

Gloss bindings for Alamofire

3 years after

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.

Related Repositories

awesome-swift

awesome-swift

A collaborative list of awesome swift resources. Feel free to contribute! ...

Gloss

Gloss

A shiny JSON parsing library in Swift :sparkles: ...

awesome-swift

awesome-swift

A curated list of awesome Swift frameworks, libraries and software. ...

Mastodon.swift

Mastodon.swift

A Swift / RxSwift / Moya / Gloss based API client for Mastodon instances. ...

awesome-swift

awesome-swift

A collaborative list of awesome swift resources. Feel free to contribute! ...


Top Contributors

spxrogers

Releases

-   2.0.0 zip tar
-   1.0.1 zip tar
-   1.0.0 zip tar