All Projects → sua8051 → AlamofireMapper

sua8051 / AlamofireMapper

Licence: other
Mapper for Alamofire use Swift 4 decoable

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to AlamofireMapper

Serpent
A protocol to serialize Swift structs and classes for encoding and decoding.
Stars: ✭ 281 (+1461.11%)
Mutual labels:  mapper, alamofire
Detached-Mapper
An ORM friendly mapper. Allows saving entire entity graphs. Heavily inspired in GraphDiff and AutoMapper.
Stars: ✭ 89 (+394.44%)
Mutual labels:  mapper
mapper
Map tarantool tuples to php objects.
Stars: ✭ 68 (+277.78%)
Mutual labels:  mapper
Excel2Object
excel convert to .NET Object | Excel与.NET 对象进行转换,支持公式、多Sheet等功能
Stars: ✭ 35 (+94.44%)
Mutual labels:  mapper
p mybatis
mybatis深入学习代码文档以及源码解析,包含通用mapper、分页等插件的详细介绍以及使用
Stars: ✭ 22 (+22.22%)
Mutual labels:  mapper
NeoClient
🦉 Lightweight OGM for Neo4j which support transactions and BOLT protocol.
Stars: ✭ 21 (+16.67%)
Mutual labels:  mapper
Moya-Gloss
Gloss bindings for Moya
Stars: ✭ 37 (+105.56%)
Mutual labels:  alamofire
g910-gkey-macro-support
GKey support for Logitech G910 Keyboard on Linux
Stars: ✭ 85 (+372.22%)
Mutual labels:  mapper
AlamofireURLRequestConfigurable
URLRequestConfigurable for Alamofire - Even cleaner type safe routing
Stars: ✭ 22 (+22.22%)
Mutual labels:  alamofire
ObjectMapper RealmSwift
Helps to parse RealmSwift's List<Class>() and RealmOptional<T>() properties with ObjectMapper framework.
Stars: ✭ 17 (-5.56%)
Mutual labels:  objectmapper
Venflow
A brand new, fast and lightweight ORM, build for PostgreSQL.
Stars: ✭ 162 (+800%)
Mutual labels:  mapper
mongo-mapper
Easy POJO codec for MongoDB in Java
Stars: ✭ 23 (+27.78%)
Mutual labels:  mapper
realm-mapper-ios
Realm + ObjectMapper
Stars: ✭ 28 (+55.56%)
Mutual labels:  objectmapper
JSONUtilities
Easily load JSON objects and decode them into structs or classes
Stars: ✭ 57 (+216.67%)
Mutual labels:  mapper
Realm-and-Swift-Codable
How to implement Swift 4 Codable with Realm Database
Stars: ✭ 34 (+88.89%)
Mutual labels:  decodable
WhatFilm
Simple iOS app using TMDb API and RxSwift
Stars: ✭ 35 (+94.44%)
Mutual labels:  alamofire
Convertify
iOS: Convert Spotify links to Apple Music and vice versa
Stars: ✭ 27 (+50%)
Mutual labels:  alamofire
HttpUtility
HttpUtility is an open source MIT license project which is helpful in making HTTP requests and returns a decoded object from server. Right now this utility only parses JSON.
Stars: ✭ 28 (+55.56%)
Mutual labels:  decodable
AlamoRecord
An elegant yet powerful iOS networking layer inspired by ActiveRecord.
Stars: ✭ 18 (+0%)
Mutual labels:  alamofire
awesome-maps-ukraine
A curated list of maps of Ukraine, ukrainian mappers and tools that they use or develop for creating and publish maps
Stars: ✭ 35 (+94.44%)
Mutual labels:  mapper

Alamofire Mapper

An extension to Alamofire which automatically converts JSON response data into swift objects using Switf 4 Decodeable

Features

  • Automatically convert JSON to Swift object
  • Don't need to map field by field, allow custom field name
  • Support object & array & nested object
  • Support decode Datetime field with timestamp, iso8601 format
  • Easy to use

Installation

AlamofireMapper can be added to your project using Cocoapods by adding the following line to your Podfile:

pod 'AlamofireMapper'

Note: maybe you need to run pod repo update before pod install

Usage

Raw json response from server

{
   "page":1,
   "per_page":3,
   "total":12,
   "total_pages":4,
   "data":[
      {
         "id":1,
         "first_name":"George",
         "last_name":"Bluth",
         "avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/calebogden/128.jpg"
      },
      {
         "id":2,
         "first_name":"Janet",
         "last_name":"Weaver",
         "avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
      },
      {
         "id":3,
         "first_name":"Emma",
         "last_name":"Wong",
         "avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/olegpogodaev/128.jpg"
      }
   ]
}

Swift class just conform Decodeable

class UserResponse: Decodable {
    var page: Int!
    var per_page: Int!
    var total: Int!
    var total_pages: Int!
    
    var data: [User]?
}

class User: Decodable {
    var id: Double!
    var first_name: String!
    var last_name: String!
    var avatar: String!
}

Then you can use the extension as the follows:

import Alamofire
import AlamofireMapper

let url1 = "https://raw.githubusercontent.com/sua8051/AlamofireMapper/master/user1.json"
        Alamofire.request(url1, method: .get
            , parameters: nil, encoding: URLEncoding.default, headers: nil).responseObject { (response: DataResponse<UserResponse>) in
                switch response.result {
                case let .success(data):
                    dump(data)
                case let .failure(error):
                    dump(error)
                }
        }

Support array response:

let url3 = "https://raw.githubusercontent.com/sua8051/AlamofireMapper/master/user2.json"
        Alamofire.request(url3, method: .get
            , parameters: nil, encoding: URLEncoding.default, headers: nil).responseObject { (response: DataResponse<[User]>) in
                switch response.result {
                case let .success(data):
                    dump(data)
                case let .failure(error):
                    dump(error)
                }
        }

You can custom decode key

class Movie: Decodable {
    var id: String!
    var name: String!
    var movies: Array<String>!
    var createdAt: Date?
    
    enum CodingKeys: String, CodingKey {
        case id
        case name
        case movies = "movies[]"
        case createdAt
    }
}

with json as the follows:

{
    "name":"paul rudd",
    "movies[]":[
        "I Love You Man",
        "Role Models"
    ],
    "id":"243",
    "createdAt":"2014-10-18T12:09:05.255Z"
}

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].