Swift 4.0 | iOS 11
我需要来自Moltin Products请求的图片网址。
我有以下功能:
private func loadProducts() {
let query = MoltinQuery(offset: nil, limit: 20, sort: nil, filter: nil, include: [.products, .files])
Moltin.product.list(withQuery: query) { (result) in
switch result {
case .failure(let error):
print("Failed to get products:\n\(error)")
case .success(let productList):
print("Got products \(productList.products)")
DispatchQueue.main.async {
self.productsCollectionView.reloadData()
}
}
}
}
这是随地吐痰:
Got products [Moltin.Product(id: "fad1eb64-2248-4798-938b-60cbffd8bf95", name: "Hat", slug: "hat", sku: "sku", description: "Some hat", commodityType: Moltin.Product.CommodityType.physical, dimensions: nil, weight: nil, files: [], collections: [], categories: [], brands: [], json: ["commodity_type": physical, "name": Hat, "sku": sku, "manage_stock": 1, "id": fad1eb64-2248-4798-938b-60cbffd8bf95, "slug": hat, "meta": {
stock = {
availability = "in-stock";
level = 5;
};
timestamps = {
"created_at" = "2018-02-21T18:57:15+00:00";
"updated_at" = "2018-02-24T06:36:40+00:00";
};
}, "status": live, "description": Some hat, "type": product, "price": <__NSSingleObjectArrayI 0x604000007f80>(
{
amount = 3499;
currency = USD;
"includes_tax" = 1;
}
)
, "relationships": {
"main_image" = {
data = {
id = "e016d89b-13e3-40e4-a247-24c1d00a1411";
type = "main_image";
};
};
}], prices: [Moltin.Price(amount: 3499, currency: "USD", includesTax: true, json: ["includes_tax": 1, "currency": USD, "amount": 3499])], displayPriceWithTax: nil, displayPriceWithoutTax: nil)]
有没有人成功拉过main_image的网址?...它只提供图片ID&amp;类型。
答案 0 :(得分:0)
我和Moltin一起发了一张票。
他们现在已将API调用更新为以下内容:
private func loadProducts() {
let query = MoltinQuery(offset: nil, limit: 20, sort: nil, filter: nil, include: [.main_image])
Moltin.product.list(withQuery: query) { (result) in
switch result {
case .failure(let error):
print("Failed to get products:\n\(error)")
case .success(let productList):
print(productList)
DispatchQueue.main.async {
self.productsCollectionView.reloadData()
}
}
}
}