filter() by for loop or many objects

I have json as below.

{
  "offersCount": 50,
  "warnings": [
    "Requested currency was USD, but rates returned in EUR"
  ],
  "filters": {
    "priceFrom": 143.89,
    "priceTo": 291.53,
    "airlines": [
      "QR",
      "G9",
      "WY",
      "SV",
      "EY",
      "UL",
      "AI",
      "KU",
      "9W",
      "J9",
      "GF"
    ],
    "durationFrom": 235,
    "durationTo": 550
  },
  "processed": true,
  "offers": [
    {
      "offerKey": "abcd",
      "available": true,
      "validatingAirlines": [
        "GF"
      ],
      "supplierCode": "abcd",
      "flightTariff": "E",
      "fareTypeForPassengers": [],
      "itinerary": [
        {
          "duration": 290,
          "segments": [
            {
              "marketingAirline": "GF",
              "operatingAirline": "GF",
              "flightNumber": "214",
              "aircraftCode": "321",
              "aircraftName": "Airbus A321-100/200",
              "categoryClass": {
                "code": "E",
                "classType": "ECONOMY"
              },
              "departureAirportCode": "KWI",
              "departureDate": "2018-08-20 11:35",
              "arrivalAirportCode": "BAH",
              "arrivalDate": "2018-08-20 12:40",
              "stopQuantity": 0,
              "stopLocations": [],
              "flightSegmentName": "KWI - BAH",
              "marketingAirlineName": "Gulf Air ",
              "operatingAirlineName": "Gulf Air ",
              "validatingAirline": "GF",
              "validatingAirlineName": "Gulf Air ",
              "duration": 65,
              "rph": "11"
            },
            {
              "marketingAirline": "GF",
              "operatingAirline": "GF",
              "flightNumber": "56",
              "aircraftCode": "321",
              "aircraftName": "Airbus A321-100/200",
              "categoryClass": {
                "code": "E",
                "classType": "ECONOMY"
              },
              "departureAirportCode": "BAH",
              "departureDate": "2018-08-20 22:40",
              "arrivalAirportCode": "BOM",
              "arrivalDate": "2018-08-21 04:55",
              "stopQuantity": 0,
              "stopLocations": [],
              "flightSegmentName": "BAH - BOM",
              "marketingAirlineName": "Gulf Air ",
              "operatingAirlineName": "Gulf Air ",
              "validatingAirline": "GF",
              "validatingAirlineName": "Gulf Air ",
              "duration": 225,
              "rph": "12"
            }
          ]
        }
      ],
      "salesTerms": [
        {
          "type": "CLIENT",
          "price": {
            "currency": "EUR",
            "amount": 160.38,
            "taxesAndFees": []
          },
          "originalCurrency": "EUR",
          "priceDetails": [
            {
              "flightName": "KWI-BOM",
              "passengerType": "ADT",
              "passengerTypeCount": 1,
              "baseFare": 147.99,
              "taxesAndFees": 12.39
            }
          ]
        }
      ]
    },
    {
      "offerKey": "abcd",
      "available": true,
      "validatingAirlines": [
        "GF"
      ],
      "supplierCode": "abcd",
      "flightTariff": "E",
      "fareTypeForPassengers": [],
      "itinerary": [
        {
          "duration": 290,
          "segments": [
            {
              "marketingAirline": "GF",
              "operatingAirline": "GF",
              "flightNumber": "212",
              "aircraftCode": "320",
              "aircraftName": "Airbus A320-100/200 ",
              "categoryClass": {
                "code": "E",
                "classType": "ECONOMY"
              },
              "departureAirportCode": "KWI",
              "departureDate": "2018-08-20 06:50",
              "arrivalAirportCode": "BAH",
              "arrivalDate": "2018-08-20 07:55",
              "stopQuantity": 0,
              "stopLocations": [],
              "flightSegmentName": "KWI - BAH",
              "marketingAirlineName": "Gulf Air ",
              "operatingAirlineName": "Gulf Air ",
              "validatingAirline": "GF",
              "validatingAirlineName": "Gulf Air ",
              "duration": 65,
              "rph": "11"
            },
            {
              "marketingAirline": "GF",
              "operatingAirline": "GF",
              "flightNumber": "64",
              "aircraftCode": "321",
              "aircraftName": "Airbus A321-100/200",
              "categoryClass": {
                "code": "E",
                "classType": "ECONOMY"
              },
              "departureAirportCode": "BAH",
              "departureDate": "2018-08-20 11:20",
              "arrivalAirportCode": "BOM",
              "arrivalDate": "2018-08-20 17:35",
              "stopQuantity": 0,
              "stopLocations": [],
              "flightSegmentName": "BAH - BOM",
              "marketingAirlineName": "Gulf Air ",
              "operatingAirlineName": "Gulf Air ",
              "validatingAirline": "GF",
              "validatingAirlineName": "Gulf Air ",
              "duration": 225,
              "rph": "12"
            }
          ]
        }
      ],
      "salesTerms": [
        {
          "type": "CLIENT",
          "price": {
            "currency": "EUR",
            "amount": 160.38,
            "taxesAndFees": []
          },
          "originalCurrency": "EUR",
          "priceDetails": [
            {
              "flightName": "KWI-BOM",
              "passengerType": "ADT",
              "passengerTypeCount": 1,
              "baseFare": 147.99,
              "taxesAndFees": 12.39
            }
          ]
        }
      ]
    },
    {
      "offerKey": "abcd",
      "available": true,
      "validatingAirlines": [
        "GF"
      ],
      "supplierCode": "abcd",
      "flightTariff": "E",
      "fareTypeForPassengers": [],
      "itinerary": [
        {
          "duration": 290,
          "segments": [
            {
              "marketingAirline": "GF",
              "operatingAirline": "GF",
              "flightNumber": "220",
              "aircraftCode": "320",
              "aircraftName": "Airbus A320-100/200 ",
              "categoryClass": {
                "code": "E",
                "classType": "ECONOMY"
              },
              "departureAirportCode": "KWI",
              "departureDate": "2018-08-20 22:50",
              "arrivalAirportCode": "BAH",
              "arrivalDate": "2018-08-20 23:55",
              "stopQuantity": 0,
              "stopLocations": [],
              "flightSegmentName": "KWI - BAH",
              "marketingAirlineName": "Gulf Air ",
              "operatingAirlineName": "Gulf Air ",
              "validatingAirline": "GF",
              "validatingAirlineName": "Gulf Air ",
              "duration": 65,
              "rph": "11"
            },
            {
              "marketingAirline": "GF",
              "operatingAirline": "GF",
              "flightNumber": "64",
              "aircraftCode": "321",
              "aircraftName": "Airbus A321-100/200",
              "categoryClass": {
                "code": "E",
                "classType": "ECONOMY"
              },
              "departureAirportCode": "BAH",
              "departureDate": "2018-08-21 11:20",
              "arrivalAirportCode": "BOM",
              "arrivalDate": "2018-08-21 17:35",
              "stopQuantity": 0,
              "stopLocations": [],
              "flightSegmentName": "BAH - BOM",
              "marketingAirlineName": "Gulf Air ",
              "operatingAirlineName": "Gulf Air ",
              "validatingAirline": "GF",
              "validatingAirlineName": "Gulf Air ",
              "duration": 225,
              "rph": "12"
            }
          ]
        }
      ],
      "salesTerms": [
        {
          "type": "CLIENT",
          "price": {
            "currency": "EUR",
            "amount": 160.38,
            "taxesAndFees": []
          },
          "originalCurrency": "EUR",
          "priceDetails": [
            {
              "flightName": "KWI-BOM",
              "passengerType": "ADT",
              "passengerTypeCount": 1,
              "baseFare": 147.99,
              "taxesAndFees": 12.39
            }
          ]
        }
      ]
    }
  ]
}

For better view, you can copy the json on http://jsonviewer.stack.hu/ & click Viewer on the website. This will show the data in tree format.

What I want to know from this object

  1. Get airlines names those are there in filters > airlines. Airline name can be take from offers > itinerary > segments > validatingAirlineName by comparing to validatingAirline.

  2. Get Minimum fare for the flight by the airline for the airlines that are there in filters. Fare can be collected from offers > salesTerms > price > amount.

Currently I am doing using for loop to get the airline names, however I see those are too much for loops. Below is the code I used.

for i in 0..<(searchFlightResponse.filters?.airlines?.count)! {
    mSt001 = (searchFlightResponse.filters?.airlines![i])!
    isBreaked = 0

    flightFilterData002 = FlightFilterData()
    flightFilterData002.flightCode = mSt001

    for j in 0..<searchFlightsArray.count {
        for k in 0..<(searchFlightsArray[j].itinerary?.count)! {
            for l in 0..<(searchFlightsArray[j].itinerary![k].segments?.count)! {
                mSt002 = searchFlightsArray[j].itinerary![k].segments![l].validatingAirline!
                if (mSt001==mSt002) {
                    // this is where I get flight name
                    flightFilterData002.flightName = searchFlightsArray[j].itinerary![k].segments![l].validatingAirlineName!
                    isBreaked = 1
                    break
                }
            }

            if (isBreaked==1) {
                break
            }
        }

        if (isBreaked==1) {
            break
        }
    }

    flightFilterData001.append(flightFilterData002)
}

I could have get the flights like below,

tempFlights = searchFlightArray.filter() {($0.itinerary![0].segments![0].validatingAirline)! == "KU"}

however problem is at segments![0].

As segments is array and it can be multiple, I am looking for a way where I can have segments![0] to segments[segments.count-1]

This is the most important point I am looking for.

Once I have above array, I can do the sorting for the minimum price.

tempFlights = tempFlights.sorted(by : { CGFloat(($0.salesTerms![0].price?.amount)!) < CGFloat(($1.salesTerms![0].price?.amount)!) })