From server response i'm getting this 5 array of arrays (Some of them is array of arrays)
What i want is replace matching value from array "Legs" () with full array that have matching value. For example if value Legs["Id"] matching with value Itineraries ["OutboundLegId"] i want to replace full array "Itineraries" with this value
1st:
Itineraries = (
{
BookingDetailsLink = {
Body = "";
Method = PUT;
Uri = "";
};
InboundLegId = "10081-1701231145--31722-1-16216-1701231854";
OutboundLegId = "16216-1701222315--31722-1-10081-1701230921";
PricingOptions = (
{
Agents = (
4132306
);
DeeplinkUrl = "http://partners.api";
Price = 706;
QuoteAgeInMinutes = 121;
}
);
},
2nd:
Legs = (
{
Arrival = "2017-01-22T20:33:00";
Carriers = (
870
);
Departure = "2017-01-22T08:59:00";
DestinationStation = 10081;
Directionality = Outbound;
Duration = 514;
FlightNumbers = (
{
CarrierId = 870;
FlightNumber = 2288;
},
{
CarrierId = 870;
FlightNumber = 178;
}
);
Id = "16216-1701220859--32171-1-10081-1701222033";
JourneyMode = Flight;
OperatingCarriers = (
870
);
OriginStation = 16216;
SegmentIds = (
0,
1
);
Stops = (
13411
);
},
that code shows how convert data in to the objects:
let agents: Array = json["Agents"].arrayValue
let carriers: Array = json["Carriers"].arrayValue
let places: Array = json["Places"].arrayValue
let legs: Array = json["Legs"].arrayValue
let ss: Array = json["Itineraries"].arrayValue
let itineraries: Array = json["Itineraries"].arrayValue.flatMap({$0["PricingOptions"].arrayValue})
That what i want but not fully understand how to prevent to swift code:
for legID in legs {
if legs.id.match with itineraries.id {
legs.id.apped(itineraries)
}
}
struct Legand astruct Itinerary(and possibly alsoFlight,Agent,Carrier, etc). Taking the trouble to break this down to types will dramatically simplify your algorithms. Then you can easily write methods likehasMatchingItineraryor make Itinerary Equatable, or anything else you need.