Latest 2.8
Homepage https://github.com/bmoliveira/Moya-ObjectMapper
License MIT
Platforms ios 8.0, osx 10.10, watchos 3.0, tvos 9.0
Authors

CocoaPods
Swift 4.2

ObjectMapper bindings for
Moya for easier JSON serialization.
Includes RxSwift bindings as well.

Installation

CocoaPods

pod 'Moya-ObjectMapper'

The subspec if you want to use the bindings over RxSwift.

pod 'Moya-ObjectMapper/RxSwift'

The subspec if you want to use the bindings over ReactiveSwift.

pod 'Moya-ObjectMapper/ReactiveSwift'

Usage

Create a Class or Struct which implements the Mappable protocol.

import Foundation
import ObjectMapper

// MARK: Initializer and Properties
struct Repository: Mappable {

  var identifier: Int!
  var language: String?
  var url: String!

  // MARK: JSON
  init?(map: Map) { }

  mutating func mapping(map: Map) {
    identifier <- map["id"]
    language <- map["language"]
    url <- map["url"]
  }

}

1. Without RxSwift and ReactiveSwift

GitHubProvider.request(.userRepositories(username), completion: { result in

    var success = true
    var message = "Unable to fetch from GitHub"

    switch result {
    case let .success(response):
        do {
            if let repos = try response.mapArray(Repository) {
              self.repos = repos
            } else {
              success = false
            }
        } catch {
            success = false
        }
        self.tableView.reloadData()
    case let .failure(error):
        guard let error = error as? CustomStringConvertible else {
            break
        }
        message = error.description
        success = false
    }
})

2. With RxSwift

GitHubProvider.request(.userRepositories(username))
  .mapArray(Repository.self)
  .subscribe { event -> Void in
    switch event {
    case .next(let repos):
      self.repos = repos
    case .error(let error):
      print(error)
    default: break
    }
  }.addDisposableTo(disposeBag)

2. With ReactiveSwift

GitHubProvider.request(.userRepositories(username))
  .mapArray(Repository.self)
  .start { event in
    switch event {
    case .value(let repos):
      self.repos = repos
    case .failed(let error):
      print(error)
    default: break
    }
  }

Contributing

Issues and pull requests are welcome!

Author

Ivan Bruel @ivanbruel

Maintainers

Bruno Oliveira @bmoliveira

License

Moya-ObjectMapper is released under an MIT license. See LICENSE for more information.

Latest podspec

{
    "name": "Moya-ObjectMapper",
    "version": "2.8",
    "summary": "ObjectMapper bindings for Moya",
    "description": "[ObjectMapper](https://github.com/Hearst-DD/ObjectMapper) bindings forn[Moya](https://github.com/Moya/Moya) for easier JSON serialization.nIncludes [RxSwift](https://github.com/ReactiveX/RxSwift/) bindings as well.nInstructions on how to use it are inn[the README](https://github.com/bmoliveira/Moya-ObjectMapper).",
    "homepage": "https://github.com/bmoliveira/Moya-ObjectMapper",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Ivan Bruel": "[email protected]"
    },
    "social_media_url": "http://twitter.com/ivanbruel",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "watchos": "3.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/bmoliveira/Moya-ObjectMapper.git",
        "tag": "2.8"
    },
    "default_subspecs": "Core",
    "subspecs": [
        {
            "name": "Core",
            "source_files": "Source/*.swift",
            "dependencies": {
                "Moya": [
                    "~> 12.0"
                ],
                "ObjectMapper": [
                    "~> 3.4"
                ]
            },
            "frameworks": "Foundation"
        },
        {
            "name": "RxSwift",
            "source_files": "Source/RxSwift/*.swift",
            "dependencies": {
                "Moya-ObjectMapper/Core": [],
                "RxSwift": [
                    "~> 4"
                ],
                "Moya/RxSwift": []
            }
        },
        {
            "name": "ReactiveSwift",
            "source_files": "Source/ReactiveSwift/*.swift",
            "dependencies": {
                "Moya-ObjectMapper/Core": [],
                "Moya/ReactiveSwift": [],
                "ReactiveSwift": []
            }
        }
    ]
}

Pin It on Pinterest

Share This