【发布时间】:2017-02-26 20:11:58
【问题描述】:
我正在尝试获取数组“reviewArray”中所有值的总和。在网上查找内容后,我设置了 self.reviewArray.reduce,但我收到错误消息,我不太确定到底该怎么做“无法将类型 '(String,) -> String' 的值转换为预期的参数类型 '(, String) -> _'" 我该如何解决这个问题?
这是我的代码
var reviewArray = [String]()
func testForGettingAllValues(){
let uid = user2?.id
let ref = FIRDatabase.database().reference().child("userRating").child(uid!)
ref.queryOrdered(byChild: "ratingNumber").observe(.value, with: {(snapshot) in
if snapshot.exists(){
if let values = snapshot.value as? [String: AnyObject]{
for reviews in values {
if let userReviews = reviews.value["ratingNumber"] as? String{
self.reviewArray.append(userReviews)
print("this is to check what is inside of the array", self.reviewArray)
//This is where i'm trying to find the sum of all the values inside of my array
var ratingSum = self.reviewArray.reduce(0,{$0 + $1})
}
}
}
}
})
}
}
【问题讨论】:
标签: ios arrays swift firebase firebase-realtime-database