1

I am obtaining a json object containing an array of objects. I am willing to parse this json using the lib EVReflection.

The operation takes a while, so I decided to monitorize the steps I'm taking, and realized the parsing of the json can take up to 20 seconds depending on the device.

Using iPhone SE / iOS 11.4 it takes 4 seconds aprox.
Using iPhone 5 / iOS 10.3 it takes 20 seconds aprox.

I am wondering if such variation is normal just depending on devices/OS.

Should I just use another lib or is there anything I can do to speed up the operation?

This is the code I'm using:

func getParkings(update: Bool) -> Observable<[ParkingEvo]> {
        if let x = parkings, !update {
            return Observable.just(x)
        } else {
            print("STEP 1: Calling API for parkings \(NSDate())")
            return RxAlamofire.string(.get, PARKINGS_URL, parameters: getParameters(), headers: nil)
                .map { self.parseParkings(json: $0) }
                .do(onNext: { self.storeParkings($0) })
        }
    }

private func parseParkings(json: String) -> [ParkingEvo]{
        print("STEP 2: Proceed to parse json \(NSDate())")
        let parkingsDTO = ParkingsDTO(json: json)
        print("STEP 3: ParkingsDTO created \(NSDate())")

        return parkingsDTO.items
    }

Between STEP2 and STEP3 there is the mentioned delay. Any idea on how to optimize this?

Thank you in advance.

jordivilagut
  • 333
  • 2
  • 9
  • I think that for better performance you should not use library based on reflection. – Roman Podymov Jun 28 '18 at 16:08
  • 1
    I do not have any experience with `EVReflection`, but code written using the `Codable` protocol produces fully compiled code and works even nicer than typical reflection code I have seen (as you end up with nicely typed objects very quickly). In order to judge your timings you should post an example record of your JSON and the number of records you typically get. – Patru Jun 28 '18 at 17:53

2 Answers2

0

Try SwiftyJSON for parsing instead it is fast an easy check Hacking with swift

It is project 7 which you need to check

AD Progress
  • 4,190
  • 1
  • 14
  • 33
0

For the record I ended up using ObjectMapper instead of EVReflection and spared 80% of the parsing time.

jordivilagut
  • 333
  • 2
  • 9