Skip to content

Instantly share code, notes, and snippets.

@akshitzaveri
Created April 23, 2020 18:35
Show Gist options
  • Save akshitzaveri/9290fa034fc8bb657e4a92d1bc4c6046 to your computer and use it in GitHub Desktop.
Save akshitzaveri/9290fa034fc8bb657e4a92d1bc4c6046 to your computer and use it in GitHub Desktop.
typealias GetProductsCompletionHandler = ([Product]) -> Void
func getProductsFromCart(_ completion: @escaping GetProductsCompletionHandler) {
self.db.collection("cart").getDocuments { (snapshot, error) in
// Handle error
if error != nil {
completion([])
return
}
// Convert firebase dictionary data to Product object
let products: [Product] = snapshot?.documents.compactMap({ Product(from: $0.data()) }) ?? []
completion(products)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment