I am sending my product array to firebase, but I want to delay while doing this, at the same time I send my array in a split way.
I want the part that says // this line below for 10 seconds, I can use a timer for this, but I don’t know how to do it.
func viewItemInList(items: [ProductModel]) {
var parameters: [String:Any] = [:]
var parameter = [parameters]
let chunkedArray = items.chunked(into: 4)
for array in chunkedArray {
parameter.removeAll()
for index in 0..<array.count {
let item = array[index]
parameters = [ AnalyticsParameterItemID: item.sku ?? "",
AnalyticsParameterItemName: item.name ?? "",
//AnalyticsParameterItemCategory: categoryName,
// AnalyticsParameterItemVariant: self.getColorFromWishList(wishListItem: item)
AnalyticsParameterItemBrand: "Skechers",
AnalyticsParameterPrice: item.price?.clearPrice() ?? 0.0
]
parameters[AnalyticsParameterIndex] = index
parameter.append(parameters)
}
parameters[AnalyticsParameterItems] = parameter
**Analytics.logEvent(AnalyticsEventViewItemList, parameters: parameters)** //this line
}
}
2
Answers
I used sleep and DispatchQueue.global
You can check while you have reached the last element and then do your task. Here is your updated function-