0
我目前正試圖返回所有在我的表格視圖中有3個屬性等於「藝術」,「音樂」&「體育」的用戶。具有3個不等於這3個字符串的屬性的其他用戶將不會顯示在我的表格視圖中。我如何實現這一目標?目前,我只能檢查ONE屬性是否等於ONE字符串就像我在下面的示例中。我有我的數據庫樹的圖像,以及我目前的代碼。任何感謝任何幫助。謝謝!如何檢查Firebase數據庫中的3個或更多值是否相同?
class User: NSObject {
var name: String?
var email: String?
var numberId: String?
var attribute1: String?
var attribute2: String?
var attribute3: String?
var password: String?
var profileImageUrl: String?
}
func fetchUser() {
FIRDatabase.database().reference().child("users").queryOrdered(byChild: "attribute1").queryEqual(toValue: "art").observe(.childAdded, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let user = User()
user.setValuesForKeys(dictionary)
self.users.append(user)
DispatchQueue.main.async(execute: {
self.tableView.reloadData()
})
}
}, withCancel: nil)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! UserCell
let user = users[indexPath.row]
cell.textLabel?.text = user.name
cell .detailTextLabel?.text = user.email
if let profileImageUrl = user.profileImageUrl {
cell.profileImageView.loadImageUsingCachWithUrlString(urlString: profileImageUrl)
}
return cell
}