Giter Club home page Giter Club logo

alamofirejsontoobjects's Introduction

AlamofireJsonToObjects

Build Status Issues Documentation Stars

Version Language Platform Support License

Git Twitter ![LinkedIn](https://img.shields.io/badge/linkedin-Edwin Vermeer-blue.svg?style=flat) Website [eMail](mailto:[email protected]?SUBJECT=About AlamofireJsonToObjects)

With AlamofireJsonToObjects it's extremely easy to fetch a json feed and parse it into objects. No property mapping is required. Reflection is used to put the values in the corresponding properties.

AlamofireJsonToObjects is based on the folowing libraries:

  • Alamofire is an elegant HTTP Networking library in Swift
  • EVReflection is used to parse the JSON result to your objects

This library was greatly inspired by AlamofireObjectMapper

Run the tests to see AlamofireJsonToObjects in action.

Using AlamofireJsonToObjects in your own App

'AlamofireJsonToObjects' is available through the dependency manager CocoaPods. You do have to use cocoapods version 0.36 or later

You can just add AlamofireJsonToObjects to your workspace by adding the folowing 2 lines to your Podfile:

use_frameworks!
pod "AlamofireJsonToObjects"

I have now moved on to Swift 2. If you want to use AlamofireJsonToObjects, then get that version by using the podfile command:

use_frameworks!
pod "AlamofireJsonToObjects", '~> 1.0'

Version 0.36 of cocoapods will make a dynamic framework of all the pods that you use. Because of that it's only supported in iOS 8.0 or later. When using a framework, you also have to add an import at the top of your swift file like this:

import AlamofireJsonToObjects

If you want support for older versions than iOS 8.0, then you can also just copy the AlamofireJsonToObjects.swift to your app.

Sample code

class WeatherResponse: EVObject {
    var location: String?
    var three_day_forecast: [Forecast] = [Forecast]()
}

class Forecast: EVObject {
    var day: String?
    var temperature: NSNumber?
    var conditions: String?
}

class AlamofireJsonToObjectsTests: XCTestCase {
    func testResponseObject() {
        let URL = "https://raw.githubusercontent.com/evermeer/AlamofireJsonToObjects/master/AlamofireJsonToObjectsTests/sample_json"
        Alamofire.request(.GET, URL)
           .responseObject { (response: Result<WeatherResponse, NSError>) in
           if let result = response.value {
            // That was all... You now have a WeatherResponse object with data
           }
        }
        waitForExpectationsWithTimeout(10, handler: { (error: NSError!) -> Void in
            XCTAssertNil(error, "\(error)")
        })
    }
}

The code above will pass the folowing json to the objects:

{  "location": "Toronto, Canada",    
   "three_day_forecast": [
      { "conditions": "Partly cloudy",
        "day" : "Monday",
        "temperature": 20 
      }, { 
        "conditions": "Showers",
        "day" : "Tuesday",
        "temperature": 22 
      }, { 
        "conditions": "Sunny",
        "day" : "Wednesday",
        "temperature": 28 
      }
   ]
}

License

AlamofireJsonToObjects is available under the MIT 3 license. See the LICENSE file for more info.

My other libraries:

Also see my other open source iOS libraries:

  • EVReflection - Swift library with reflection functions with support for NSCoding, Printable, Hashable, Equatable and JSON
  • EVCloudKitDao - Simplified access to Apple's CloudKit
  • EVFaceTracker - Calculate the distance and angle of your device with regards to your face in order to simulate a 3D effect
  • EVURLCache - a NSURLCache subclass for handling all web requests that use NSURLReques
  • AlamofireJsonToObject - An Alamofire extension which converts JSON response data into swift objects using EVReflection
  • AlamofireXmlToObject - An Alamofire extension which converts XML response data into swift objects using EVReflection and XMLDictionary
  • AlamofireOauth2 - A swift implementation of OAuth2 using Alamofire
  • EVWordPressAPI - Swift Implementation of the WordPress (Jetpack) API using AlamofireOauth2, AlomofireJsonToObjects and EVReflection (work in progress)
  • PassportScanner - Scan the MRZ code of a passport and extract the firstname, lastname, passport number, nationality, date of birth, expiration date and personal numer.

alamofirejsontoobjects's People

Contributors

evermeer avatar

Watchers

 avatar  avatar

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.