swiftxcodecontrolstinder

How to make only male or female users show on a tinder style app


I bought the udemy tutorial on how to make a tinder app by 'zero2launch' and followed it and it works perfectly, however, the users on the cards are male and female and I would like to find a way to - using segmented control - to only show male or female.

I have tried messaging them and not got a reply back yet after a few days so I am now turning to the stackOverflow community to help me.

I believe this the appropriate bit of code

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)
                })
            }
        }
    }

}

Any help would be MASSIVELY appreciated!


Solution

  • I still dont understand what your concrete problem is? You might be able to use this:

    @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 }
        }
    }
    

    and connect this action to your segmented control