2017-07-15 164 views
1

所以我有一個名爲「類」的解析服務器中的類,我試圖在我的程序內部實現一個錯誤檢查查詢。但是,當我嘗試錯誤地檢查我的查詢以搜索類時,程序總是說搜索是成功的,即使該類類型的對象不在查詢中,Xcode項目也會正確構建。下面是代碼:錯誤檢查無法正確解析查詢

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

這裏是我的應用程序內的搜索按鈕:

Screenshot of Simulator

什麼可能出問題,使分析查詢檢查始終打印成功?

回答

0

我想你錯過了你的查詢中的成功聲明。

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