如何仅在火种风格的应用上显示男性或女性用户

时间:2019-07-09 08:40:26

标签: swift xcode controls tinder

我购买了有关如何通过“ zero2launch”制作火种应用程序的udemy教程,并遵循了它,并且效果很好,但是,卡片上的用户是男性还是女性,我想找到一种方法-使用分段控制-仅显示男性或女性。

几天后,我尝试向他们发送消息,但没有得到任何回复,因此,我现在向stackOverflow社区寻求帮助。

我相信这是适当的代码

func findUsers() {

        if queryHandle != nil, myQuery != nil {
            myQuery.removeObserver(withFirebaseHandle: queryHandle!)
            myQuery = nil
            queryHandle = nil
        }

        guard let userLat = UserDefaults.standard.value(forKey: "current_location_latitude") as? String, let userLong = UserDefaults.standard.value(forKey: "current_location_longitude") as? String else {
            return
        }

        let location: CLLocation = CLLocation(latitude: CLLocationDegrees(Double(userLat)!), longitude: CLLocationDegrees(Double(userLong)!))
        self.users.removeAll()

        myQuery = geoFire.query(at: location, withRadius: distance)

        queryHandle = myQuery.observe(GFEventType.keyEntered) { (key, location) in

            if key != Api.User.currentUserId {
                Api.User.getUserInforSingleEvent(uid: key, onSuccess: { (user) in
                    if self.users.contains(user) {
                        return
                    }
                    if user.isMale == nil {
                        return
                    }
                    self.users.append(user)
                    self.setupCard(user: user)
                    print(user.username)
                })
            }
        }
    }

}

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

我仍然不明白您的具体问题是什么? 您也许可以使用此功能:

@IBAction func selectGender(_ sender: UISegmentedControl) {
    switch(sender.selectedSegmentIndex){
    case 1: // male users
        // update your cards to only list male users
        self.users = self.users.filter { $0.isMale }
    case 2: // female users
        self.users = self.users.filter { !$0.isMale }
    }
}

并将此操作连接到您的分段控件