I have one Array which has HotelId key & it's value like below
[
{
"StartPrice": 724.45,
"HotelId": 2251800,
"HotelOption": []
},
{
"StartPrice": 725.05,
"HotelId": 84357,
"HotelOption": []
}
]
now I have to iterate above array with below second array by matching it's HotelId & fetch respective data from the array
[
{
"HotelId": 5103,
"HotelName": "Abc Hotel",
"Rating": "3",
"IsRecomondedHotel": false
},
{
"HotelId": 5104,
"HotelName": "Paradise Hotel",
"Rating": "3",
"IsRecomondedHotel": false
},
{
"HotelId": 5105,
"HotelName": "Hotel Sea Rock Inn",
"Rating": "4",
"IsRecomondedHotel": false
}
]
Now the main problem is, it's working fine when first array count is normally 25-30 around, but takes usually 2-4 mins when the first array count is around 1050 & second array count is around 5000 with below code
//
print("\n******************** final hotel list preparation starts ****************"
hotelListArr = [HotelListModel]()
if let hotelListDictArr = hotelListDict, // LOGIC 2
let hotelMappingDictArr = hotelMappingDict {
for hotelListItem in hotelListDictArr {
for hotelMappingItem in hotelMappingDictArr {
if let hotelIdInList = hotelListItem["HotelId"],
let hotelIdInDetails = hotelMappingItem["HotelId"],
"\(hotelIdInList)" == "\(hotelIdInDetails)" {
let obj = HotelListModel()
obj.setValuesForKeys(hotelListItem)
obj.setValuesForKeys(hotelMappingItem)
hotelListArr?.append(obj)
break
}
}
}
}
print("ends...\nhotelListArr.count: \(String(describing: hotelListArr?.count))")
With above approach gets result in Android Java around 5 seconds but in iOS Swift 4 same result takes 2-4 mins when array count is big,
Could anyone help on this to how to perform above operation very fast in iOS Swift 4?