Parsing travel duration data
Not sure if this code is correct or will compile but here is my attempt...

private class func parseTravelData(data: AnyObject!, mode: ESTMode, completion: NSDictionary? -&gt; Void) {
    let receivedData = data as? NSDictionary
    let routes = receivedData?["routes"] as? NSArray
    let legs = routes?.firstObject?["legs"] as? NSDictionary

    if let firstLeg = legs?.firstObject as? NSDictionary {
        let firstLegDurationDict = firstLeg["duration"] as? NSDictionary
        let firstLegDuration = firstLegDurationDict?["value"] as? Float

        if firstLegDuration &gt; ConnectionManager().timeMax &amp;&amp; mode == .Walking {
            completion(nil) // resend using drive mode
        } else if let durationStr = firstLegDurationDict?["text"] as? String {
            let distanceDict = firstLeg["distance"] as? NSDictionary
            if let distanceStr = distanceDict?["text"] as? String {
                completion(["duration": durationStr, "distance": distanceStr])
            }
        }
    }
}


Here are a few things I did to try to make the code more concise

I noticed that the interesting stuff only happens if the route contains a leg. So I was able to eliminate a few if statement blocks by using optional chaining and moving code out of the if conditions and into the receivedData, routes, and legs variables. (The individual variables are not strictly necessary but make the code more readable). So the first "if let" check happens to see if there is actually a leg in the optional legs array.

Another optimization I made is that I moved the if let d = dur block into the else statement above since the code will only proceed if duration["text"] exists. This also allowed me to eliminate the var dur: String? = nil statement as well.

I also renamed some variables for more clarity, for example I renamed v to firstLegDuration.

I was able to eliminate the if let v block since if v (which is now firstLegDuration) is nil then v &gt; ConnectionManager().timeMax will be false since nil &gt; AnyObject == false.

One thing I noticed that the completion does not get called in all cases, which to me seems weird, so if there is an error or missing data then nothing will happen.