【发布时间】:2017-02-10 10:39:53
【问题描述】:
我尝试将我的代码 func 转换为 func 到 Swift 3。我不得不说我之前有完整的工作项目。现在我遇到了问题,我没有错误,只有一些警告,但有些功能没有被执行。这应该是什么原因造成的?
我只假设那些给定的功能是错误的,因为这些是我什至没有得到任何东西的部分print。
这些是我以前使用但不适用于 Swift 3 的一些函数:
//With this I get selected brand products values like product name, nicotine, flavor etc..
let ref = FIRDatabase.database().reference().child("Snuses").queryOrdered(byChild: "Brand").queryEqual(toValue: brandName)
ref.observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.exists(){
if let products = (snapshot.value as AnyObject).allValues as? [[String:AnyObject]]{
self.productsValue = products
self.productsTable.reloadData()
}
}
})
//With this fucntion I get the products count.
let ref = FIRDatabase.database().reference().child("Snuses").queryOrdered(byChild: "Brand").queryEqual(toValue: filteredBrands[indexPath.row])
ref.observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.exists(){
if let products = (snapshot.value as AnyObject).allValues as? [[String:AnyObject]]{
var count = (snapshot.childrenCount)
snusProductCountLabel.text = "\(count) products"
}
}
})
//Parse snus brands
func parseSnuses(){
let ref = FIRDatabase.database().reference().child("Brands").queryOrderedByKey()
ref.observe(.childAdded, with: { (snapshot) in
self.brands.append(snapshot.key)
print(snapshot.key)
self.snusBrandsTableView.reloadData()
}){ (error) in
}
任何我能做的不同的事情请告诉我!这些函数在不同的ViewControllers。
编辑:这是我的 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
},
这些是安全规则:
{
"rules": {
".read": "true",
".write": "true",
"Snuses": {
".indexOn": "Brand"
}
}
}
【问题讨论】:
-
您到底看到了什么,就错误而言?不清楚是什么问题...
-
没有错误只是代码没有给出任何东西。
-
那么“代码没有给出任何东西”是什么意思呢?代码应该“给你”什么?
-
使用您的 JSON 树更新您的问题,并且您的安全规则还会说明您的用户在使用任何功能之前是否经过身份验证。其次它太宽泛了......
-
我更新了我的问题。在代码 cmets 中,您会看到山雀应该给出什么。例如,在最后一个中,它应该给出所有“品牌”,例如“Catch”。
标签: ios swift firebase tableview firebase-realtime-database