Home

Awesome

AlamofireXmlToObjects

🚨 This is now a subspec of EVReflection and the code is maintained there. 🚨

You can install it as a subspec like this:

use_frameworks!
pod "EVReflection/AlamofireXML"

Besideds this subspec there are also subspecs for: XML, AlamofireXML, Moya, MoyaRxSwift and MoyaReflectiveSwift

<!--- [![Circle CI](https://img.shields.io/circleci/project/evermeer/AlamofireXmlToObjects.svg?style=flat)](https://circleci.com/gh/evermeer/AlamofireXmlToObjects) [![Build Status](https://travis-ci.org/evermeer/AlamofireXmlToObjects.svg?style=flat)](https://travis-ci.org/evermeer/AlamofireXmlToObjects) -->

Issues Documentation Stars Awesome

Version Language Platform Support License

Git Twitter ![LinkedIn](https://img.shields.io/badge/linkedin-Edwin Vermeer-blue.svg?style=flat) Website [eMail](mailto:edwin@evict.nl?SUBJECT=About AlamofireXmlToObjects)

If you have a question and don't want to create an issue, then we can Join the chat at https://gitter.im/evermeer/EVReflection (EVReflection is the base of AlamofireJsonToObjects)

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

AlamofireXmlToObjects is based on the folowing libraries:

If you have a JSON service and want the same functionality then have a look at AlamofireJsonToObjects.

At this moment the master branch is for Swift3. If you want to continue using Swift 2.2 (or 2.3) then switch to the Swift2.2 branch. Run the tests to see AlamofireXmlToObjects in action.

Using AlamofireXmlToObjects in your own App

'AlamofireXmlToObjects' is available through the dependency manager CocoaPods.

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

use_frameworks!
pod "AlamofireXmlToObjects"

You also have to add an import at the top of your swift file like this:

import AlamofireXmlToObjects

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 AlamofireXmlToObjectsTests {
    func testResponseObject() {
        let URL = "https://raw.githubusercontent.com/evermeer/AlamofireXmlToObjects/master/AlamofireXmlToObjectsTests/sample_xml"
        Alamofire.request(URL)
        .responseObject { (response: DataResponse<WeatherResponse>) in
            if let result = response.value {
               // That was all... You now have a WeatherResponse object with data
            }
        }
    }
}

The code above will parse the folowing XML into the objects:

<wheather>
   <location>Toronto, Canada</location>
   <three_day_forecast>
      <forecast>
         <conditions>Partly cloudy</conditions>
         <day>Monday</day>
         <temperature>20</temperature>
      </forecast>
      <forecast>
         <conditions>Showers</conditions>
         <day>Tuesday</day>
         <temperature>22</temperature>
      </forecast>
      <forecast>
         <conditions>Sunny</conditions>
         <day>Wednesday</day>
         <temperature>28</temperature>
      </forecast>
   </three_day_forecast>
</wheather>

Advanced object mapping

AlamofireJsonToObjects is based on EVReflection and you can use all EVReflection features like property mapping, converters, validators and key kleanup. See EVReflection for more information.

License

AlamofireXmlToObjects 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: