I have a tinder type set up and I am fetching all of the users so I can swipe on their cards. everything works smoothly except for the fact that this swipe view is also calling the data from the current user allowing them to swipe on themselves. This should not happen.
The code that I am using is
func fetchUser() {
topCardView = nil
var previousCardView: CardView?
Database.database().reference().child("jobPost").observe(.childAdded, with: { (snapshot) in
if let userDictionary = snapshot.value as? [String: AnyObject] {
let poster = Poster(dictionary: userDictionary as [String : AnyObject])
let cardView = self.setupCardFromUser(poster: poster)
self.cardViewModels.append(poster.toCardViewModel())
if let currentUser = Auth.auth().currentUser?.uid,
currentUser == poster.fromId {
cardView.removeFromSuperview()
} else if self.topCardView == nil {
self.topCardView = cardView
}
previousCardView?.nextCardView = cardView
previousCardView = cardView
}
}, withCancel: nil)
}
This allows me to call all of the data from firebase however, it is also calling the currentUsers data as well.
I thought that maybe if were to use
let currentUser = Auth.auth().currentUser?.uid
if currentUser == cardView {
cardView?.removeFromSuperview()
}
would do the job but on this, I am receiving error
Binary operator '==' cannot be applied to operands of type 'String?' and 'CardView'
does anyone know a quick fix?
Does your cardView have information about user? Maybe you can add userID field to the card view? if it's possible, you will be able to do something like this
if let currentUser = Auth.auth().currentUser?.uid,
let cardView = cardView,
currentUser == cardView.userID {
// put your code to ignore card
}
where userId - will be string type
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.