'Like and Dislike Button - Swift
First of all, I'm new to this topic. The question I'm going to ask is probably a simple one, but I couldn't find a solution. I want to put like and dislike button. When I press like or dislike, the numbers on the other line change. How can I fix this problem. @IBAction func likeButonClicked(_ sender: Any) {
let fireStoreDatabase = Firestore.firestore()
if let likeCount = Int(likeLabel.text!) {
let likeStore = ["likes" : likeCount + 1 ] as [String : Any]
fireStoreDatabase.collection("Posts").document(documentIdLabel.text!).setData(likeStore, merge: true)
likeButton.isHidden = true
dislikeButton.isHidden = false
}
} @IBAction func dislikeButonClicked(_ sender: Any) {
let fireStoreDatabase = Firestore.firestore()
if let likeCount = Int(likeLabel.text!) {
let likeStore = ["likes" : likeCount - 1 ] as [String : Any]
fireStoreDatabase.collection("Posts").document(documentIdLabel.text!).setData(likeStore, merge: true)
likeButton.isHidden = false
dislikeButton.isHidden = true
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
