Latest 1.0.1
Homepage https://github.com/tablexi/AlamofireGenome
License MIT
Platforms ios 8.0, requires ARC
Dependencies Alamofire, Genome
Authors ,

An Alamofire extension that automatically converts JSON into Swift objects using Genome.

Installation

Cocoapods

Add the following to your Podfile:

pod 'AlamofireGenome'

Carthage

Add the following to your Cartfile:

github "tablexi/AlamofireGenome"

Usage

Let’s pretend we’re interested in querying the Github API for repository information. To store retrieved data, we can define the following simple data structure:

struct GithubRepository {
  var name: String!
  var fullName: String!
  var description: String!
}

extension GithubRepository: BasicMappable {
  mutating func sequence(map: Map) throws {
    try name <~> map["name"]
    try fullName <~> map["full_name"]
    try description <~> map["description"]
  }
}

Fetching a single object

To fetch a single repository, we can use the following code:

let url = "https://api.github.com/repos/tablexi/AlamofireGenome"
Alamofire.request(.GET, url).responseObject { (response: Response<GithubRepository, NSError>) in
  switch response.result {
    case .Success(let repository): // ...
    case .Failure(let error): // ...
  }
}

Fetching an array of objects

To fetch a list of repositories, we can use the following code:

let url = "https://api.github.com/orgs/tablexi/repos"
Alamofire.request(.GET, url).responseArray { (response: Response<[GithubRepository], NSError>) in
  switch response.result {
    case .Success(let repositories): // ...
    case .Failure(let error): // ...
  }
}

Contributing

  1. git clone <repo_url>
  2. cd AlamofireGenome
  3. ./bin/setup

Latest podspec

{
    "name": "AlamofireGenome",
    "version": "1.0.1",
    "summary": "An Alamofire extension that automatically converts JSON into Swift objects using Genome",
    "homepage": "https://github.com/tablexi/AlamofireGenome",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Dan Hodos": "[email protected]",
        "John Dzak": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/tablexi/AlamofireGenome.git",
        "tag": "v1.0.1",
        "submodules": true
    },
    "source_files": "AlamofireGenome/**/*.{h,swift}",
    "dependencies": {
        "Alamofire": [
            "~> 3.0"
        ],
        "Genome": [
            "~> 1.0"
        ]
    }
}

Pin It on Pinterest

Share This