gpt4 book ai didi

ios - 值保留在数组内部

转载 作者:行者123 更新时间:2023-11-30 12:30:04 25 4
gpt4 key购买 nike

我正在创建一个功能,根据用户在“firstLocation”、“secondLocation”、“thirdLocation”中设置的值来显示用户特定的人员。我正在检查所有 Firebase 用户,过滤并提取任何匹配的帐户。这就是我要做的事情

func fetchUser(){
FIRDatabase.database().reference().child("Users").observe(.childAdded, with: {(snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject]{
let user = User()
user.id = snapshot.key
user.setValuesForKeys(dictionary)
user.name = dictionary["name"] as! String?
user.aboutMe = dictionary["aboutMe"] as! String?
user.profileImageUrl = dictionary["profileImageUrl"] as! String?
user.firstLocation = dictionary["firstLocation"] as! String?
user.secondLocation = dictionary["secondLocation"] as! String?
user.thirdLocation = dictionary["thirdLocation"] as! String?
user.guiderMode = dictionary["guiderMode"] as! String?
self.users = self.users.filter{(($0.firstLocation?.contains(self.passedLocation!))!)&&$0.guiderMode == "True" || (($0.secondLocation?.contains(self.passedLocation!))!) || (($0.thirdLocation?.contains(self.passedLocation!))!)}
self.users.append(user)
print("The count of the users", self.users.count as Any)

self.tableView.reloadData()
}

}, withCancel:nil)
}

现在的问题是,由于某种原因,一个值总是会出现,尽管它不应该被看到,因为它不符合过滤器要求。我尝试通过执行以下操作来修复它

users.removeAll()
tableView.reloadData()

但无论如何它仍然显示

最佳答案

查看 self.users.append(user)。您始终会附加一个新用户而不对其应用过滤器,因此在调用观察回调后,用户始终至少有 1 个元素。

关于ios - 值保留在数组内部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43671825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com