JonP
JonP

Reputation: 67

SwiftyJSON extremely slow JSON iteration

I am using a lib SwiftyJSON.swift. I successfully import a valid JSON file but it's very large (500kb) (actually a gpx-file from Strava).

The code below is VERY slow, about one integration per second! Why? And what can I do about it?

for index in 0...json1["trk"]["trkseg"]["trkpt"].length-1 {

    lat = Double(json1["trk"]["trkseg"]["trkpt"][index]["@attributes"]["lat"].asString!)!

    long = Double(json1["trk"]["trkseg"]["trkpt"][index]["@attributes"]["lon"].asString!)!
}

Upvotes: 0

Views: 316

Answers (1)

dasdom
dasdom

Reputation: 14063

I think the following change could speed up your code a bit:

let array = json1["trk"]["trkseg"]["trkpt"]
for bla in array {
    lat = Double(bla["@attributes"]["lat"].asString!)!
    long = Double(bla["@attributes"]["lon"].asString!)!
}

Upvotes: 3

Related Questions