【发布时间】:2016-08-28 11:17:22
【问题描述】:
我正在尝试使function 让用户在使用application 之前从Firebase 下载所有内容,这是可选的。它应该使用户体验更好。是否可以?
现在我的JSON 包含这些字段。 JSON 实际上要长得多:
"Snuses" : {
"Catch Eucalyptus White Large" : {
"Brand" : "Catch",
"Products" : "Catch Eucalyptus White Large",
"PorionWeight" : 21.6,
"flavor" : "Tobacco, Eucalyptus",
"nicotine" : 8.0,
"PortionsCan" : 24,
"shipping weight" : 39,
"productUrl" : "https://firebasestorage.googleapis.com/v0/b/snuspedia.appspot.com/o/Catch%20Dry%20Eucalyptus%20White%20Mini.png?alt=media&token=b712f44c-a83b-4a18-b9cc-7f77897e5489"
},
我还使用 Firebase 存储,其中包含有关 (20mb) 的图像。我想parse所有信息+图像,完成后显示它们。
现在我正在为图像这样做:
if productsValue[indexPath.row]["productUrl"] != nil {
cell.snusProductImageView!.kf_setImageWithURL(NSURL(string: productsValue[indexPath.row]["productUrl"] as! String)!)
}
else {
let productImageref = productsValue[indexPath.row]["Products"] as! String
let decomposedPath = productImageref.decomposedStringWithCanonicalMapping
cell.snusProductImageView.image = nil
cell.snusProductImageView.kf_showIndicatorWhenLoading = true
FIRStorage.storage().reference().child("\(decomposedPath).png").downloadURLWithCompletion({(url, error)in
FIRDatabase.database().reference().child("Snuses").child(decomposedPath).child("productUrl").setValue(url!.absoluteString)
let resource = Resource(downloadURL: url!, cacheKey: decomposedPath)
cell.snusProductImageView.kf_setImageWithURL(url)
})
所有其他内容几乎相同。
最好的选择是什么?
【问题讨论】:
标签: json swift uitableview firebase