Created
April 23, 2020 18:35
-
-
Save akshitzaveri/9290fa034fc8bb657e4a92d1bc4c6046 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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