So I have a class in the parse server called "classes" and I tried to implement an error-checking query inside my program. The Xcode project builds properly, however, when I attempt to error check my query to search for classes, the program always says the search is a success, even though an object of that class type is not in the query. Here is the code:
@IBAction func searchClass(_ sender: Any) {
let query = PFQuery(className: "Classes")
query.findObjectsInBackground { (success, error) in
if error != nil{
self.createAlert(title: "Error", message: "Cannot find class")
} else {
self.createAlert(
title: "Success", message: "Found the query")
self.classSuccess = true
self.flipCardButton.alpha = 0
UIView.transition(from: self.classQuery, to: self.classRate, duration: 0.5, options: .transitionFlipFromRight)
self.goBackButton.alpha = 1
}
}
And here was the search button inside of my application:
What could possibly go wrong to make the parse query check always print success?
I think your missing the success statement in your query.
let query = PFQuery(className: "Classes")
query.findObjectsInBackground { (success, error) in
if error != nil{
print(error ?? "")
self.createAlert(title: "Error", message: "Cannot find class")
}
if success {
self.createAlert(
title: "Success", message: "Found the query")
self.classSuccess = true
self.flipCardButton.alpha = 0
UIView.transition(from: self.classQuery, to: self.classRate, duration: 0.5, options: .transitionFlipFromRight)
self.goBackButton.alpha = 1
} else {
self.createAlert(title: "Error", message: "Cannot find class")
}
}