Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Edwin Vermeer
    and below that there is a folder named XML
    with the code:
    import Foundation
    import RxSwift
    import Moya
    /// Extension for processing Responses into Mappable objects through ObjectMapper
    public extension ObservableType where E == Response {
        /// Maps data received from the signal into an object
        /// which implements the Mappable protocol and returns the result back
        /// If the conversion fails, the signal errors.
        public func mapXml<T: EVReflectable>(to type: T.Type) -> Observable<T> where T: NSObject {
            return flatMap { response -> Observable<T> in
                let result = try response.mapXml(to: T.self)
                return Observable.just(result)
    So indeed it should be .mapXml
    You can find a unit test if you download or clone EVReflection and search for testDownloadWheatherResponseRxSwiftXML
    The entire unit tests looks like this:
    func testDownloadWheatherResponseRxSwiftXML() {
            let expectation = self.expectation(description: "evermeer")
                .mapXml(to: WeatherResponse.self)
                .subscribe { event -> Void in
                    switch event {
                    case .next(let result):
                    case .error(let error):
                        XCTAssert(false, "no result from service")
            waitForExpectations(timeout: 10) { error in
                XCTAssertNil(error, "\(error?.localizedDescription ?? "")")
    Jeremy Boy
    Thanks for the quick reply. So there is no mapXml(toArray:)? If so, this seems to be a typo in README.md . Is there a better way to deal with something like the following? I'd like to have anObservable<[Ticket]> in the end: <tickets><ticket><id/><subject/></ticket><ticket><id/><subject/></ticket><!-- ... --></tickets>. My workaround for now is to have a TicketArray type with a field ticket: [Ticket] and do a flatMap after each request, but this doesn't seem optimal to me, I'll have to deal with several types in this project (<issues><issue/></issues>, <users><user/></users> etc.).
    Edwin Vermeer
    @seasox I think I did not make the .mapXml(toArray: because xml always has a root node. So you always have an object as the base. But… later on I added the forKeyPath parameter… Using that it could be possible to map to an array. Let me see if I can make an update for that...
    Renan Costa

    @evermeer I'm trying to use an Object that inherits from EVNetworkingObject and want the object to be set as part of the Alamofire Parameters object to the .post method.

    class CreditCard: EVNetworkingObject {
        var cardNumber : String?
        var holder : String?
        var expirationDate : String?
        var securityCode : String?
        var brand : String?
        var cardToken : String?

    I need send json of CreditCard in request body. How can I do that?

    Edwin Vermeer
    @renanalan There are varous ways to post json using alamofire. Depending on that you can take the .toJsonString, .toDictionary or .toJsonData methods on your object. For instance if you would like to post a plain json string, you would end up with something like:
    var request = URLRequest(url: url)
    request.httpMethod = HTTPMethod.post.rawValue
    request.setValue("application/json; charset=UTF-8", forHTTPHeaderField: "Content-Type")
    request.httpBody = myCreditCardObject.toJsonData()
    So it depends on your preference how you like to use Alamofire when posting data. You could use any of the objects .to* methods. If you don’t want all of your properties in the json data, then use the propertyMapping function to exclude properties.
    Bogdan Geleta
    This message was deleted
    Hi, I have an issue with EVManagedObject. When I tried to call toJsonString or toDictionary it always returns {} for me. I've tested on testCoreDataSmokeTest method. Just added print(person. toJsonString()) at CoreDataTests.swift:58 and it returns {}
    Edwin Vermeer
    @eXhausted Hmm…. Aperently reflection does not work on a NSManagedOBject. The following line of code returns 0
    Mirror(reflecting: obj).children.count
    Which means that using the Swift Mirror function for reflecting an object structure returns zero elements.
    Since that’s the base for getting information, this means that with coredata you could create an instance, but you can’t create json objects from it.
    It looks like i have to overwrite the .toJsonData and .toJsonString and use something like this:
    NSArray keys = [[[myObject entity] attributesByName] allKeys];
    dict = [myObject dictionaryWithValuesForKeys:keys];
    but then of course the swift version :)
    Edwin Vermeer
    So the Swift version will be:
        obj.dictionaryWithValues(forKeys: obj.entity.attributesByName.keys)
    Bogdan Geleta
    @evermeer got, thx
    @evermeer just FYI, attributesByName.keys doesn't return [String]
    Edwin Vermeer
    @eXhausted I see, yesterday I added code for this to EVManagedObject. Now it all works like it should (I think/hope) It’s now based on this function that I added:
    open func toDictionary(_ conversionOptions: ConversionOptions = .DefaultSerialize) -> NSDictionary {
        let keys = Array(self.entity.attributesByName.keys)
        return self.dictionaryWithValues(forKeys: keys) as NSDictionary
    I do have to fix one (unrelated) unittest before I can push it to GitHub.
    Edwin Vermeer
    @eXhausted I have pushed the EVManagedObject fix to GitHub as version 4.17.0
    Enrique Choynowski Melgarejo
    Hello @evermeer

    Is it possible to have more than one Date Formatter? because my service has two different date formatting.

    1 - yyyy-MM-dd'T'HH:mm:ss.SSSZ
    2 - yyyy-MM-dd'T'HH:mm:ssZ

    And I can't handle this with just one DateFormatter.

    Edwin Vermeer
    @Enriquecm At this moment you can only do that by using a propertyConverter for one of those dates. It was already on my mind to think of a more flexible solution for this but since there was no demand for it yet it’s still low on my todo list. I can think of one reaslonably easy fix for tis and that is that you could specify per object if you want to overrule the default date formatter. Or do you have multiple date formats in one object? Anyway… For now you should implement a propertyConverter like this:
    override open func propertyConverters() -> [(key: String, decodeConverter: ((Any?) -> ()), encodeConverter: (() -> Any?))] {
        return [( // We want a custom converter for the field isGreat
            key: "isGreat",
            // isGreat will be true if the json says 'Sure'
            decodeConverter: { self.isGreat = ($0 as? String == "Sure") },
            // The json will say 'Sure  if isGreat is true, otherwise it will say 'Nah'
            encodeConverter: { return self.isGreat ? "Sure": "Nah"})]
    But then of course while converting to and from a date instead of a boolean like this sample.
    Enrique Choynowski Melgarejo
    @evermeer I got it.! I'll keep an eye on your repository. Anyway, thank you very much for the reply. I believe the propertyConverters will work.
    Guilherme Araújo
    Hi, how can I use EVNetworkingObject when installing EVReflection via Carthage?
    I'm including the EVReflection.framework, but the compiler says Use of undeclared type 'EVNetworkingObject'
    Edwin Vermeer
    @guilhermearaujo EVNetworkingObject is part of the Alamofire subspecies. Currenly there is no Carthage framework configured for that. There is only a Carthage framework for the base EVReflection.
    Hi @everemeer, I just upgraded to swift 4 after a break and now no data gets loaded (was working in swift 3). I'm getting a "The class is not key coding compliant for the key". Keys are all basic types e.g. String. Source data is a JSON Dict. Any ideas what I'm doing wrong?
    Found the issue @objcmembers was commented out in the cocoa pod version
    Edwin Vermeer
    @guilhermearaujo I was unable to push the Swift4 version which is now on master to cocoapods because of the dependency with Moya which is still in beta for the Swift 4 version. So when you do a pod update you will get the version without @objcmembers. The moment Moya 10 is release I will push the master branch to cocoa pods.
    Got it and thanks for the response - it's all working now.
    @evermeer Hey Mate i can see that you have released the SWIFT 4 version but cocoapods still pointing to 4.19.1
    can you please please update that ?
    Edwin Vermeer 
    @hardikdevios There is a problem publishing it to cocoapods because of a dependancy with Moya which does not have published its swift 4 version. If you add the gitpath in your podfile then it will be forced to the 5.0 version.
    pod 'EVReflection', :git => 'https://github.com/evermeer/EVReflection.git'
    @evermeer yes i am already doing that and watching this repo since SWIFT 4 release, Regarding Moya i think they have updated with SWIFT 4 https://github.com/Moya/Moya/releases
    Edwin Vermeer 
    Ah, thanks! Will have a look at it later today
    King Calculator
    @evermeer_twitter does evreflection supports generic types? Im doing something like class SomeClass<T: EVObject> { init() { let t = T(json: somejson) }. the EVObject() init is invoked, but the values that the class behind the T generic are not valid... any idea why?