You have to use completion block for your function which makes server request and need to apply some more logic to show user about something is happening.
var IDs = [Int]()
var items = [Item]()
for id in IDs {
requestItem(itemId : id, finished : { (objItem : Item) -> Void in
items.append(objItem)
// Below condition is to check weather all async service call response are came then hide loader or show items to user, etc. whatever you want to do after get all calls responses
if IDs.count == items.count {
// Show item to user or perform your further operation
}
})
}
Function which has completion block
func requestItem(itemId : Int, finished: (objItem : Item) -> Void) {
print("Item details fetched!")
// Store your response in your Item class object and pass it like below
let objItem = Item() // You constructor or any other logic to store value in objItem
// Call finished when you have data initialized in your objItem object
finished(objItem)
}