I get the Data from alamofire however it's not appending. I think the reason for this is because it's happening Async. Just couldn't figure out the best way to fix this in my code. Thanks in Advance for the help.
var allItems = [Item]();
@discardableResult func createItem() -> Item {
let newItem = Item(name: "Grocery", description: "Milk Egg Cheese", priority: "High")
// let newItem1 = Item(name: "Test", description: "Tes", priority: "Test")
AF.request("https://mobile-app-i.herokuapp.com/list/list").responseJSON { response in
switch response.result {
case .success(let value):
DispatchQueue.main.async {
if let value = value as? [NSDictionary] {
for d in value {
print(d["description"])
let dataItem = Item(name: d["name"]! as! String, description: d["description"]! as! String, priority: d["priority"]! as! String)
self.allItems.append(dataItem)
}
}
}
case .failure(let error):
print(error)
}
}
// allItems.append(newItem1)
allItems.append(newItem)
return newItem
}