ios - 错误检查无法正常用于解析查询

标签 ios swift xcode parse-platform

所以我在解析服务器中有一个名为“classes”的类,我试图在我的程序中实现一个错误检查查询。 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

使解析查询检查始终打印成功可能会出现什么问题?

最佳答案

我认为您在查询中遗漏了成功语句。

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

关于ios - 错误检查无法正常用于解析查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45121228/

相关文章:

ios - 为什么我可以在没有参数的情况下初始化 UIView,但它的文档没有空的初始化程序?

swift - 如何在 iMessage 贴纸扩展中包含动画 png 序列?

ios - 具有奇怪外观的 setBackButtonBackgroundImage

ios - 如何在 iOS 中使用 AFNetworking 从 REST 接口(interface)定期轮询/拉取

ios - 使用 AVAudioPlayer 添加 iPod 均衡器效果

ios - 为什么我打开应用程序时 swift 应用程序 IPA 会崩溃?

C - 无法从 Xcode 创建新的 .txt 文件

ios - 是否可以使用静默推送来唤醒APP并接听VOIP电话?

ios - swift : deinit is not calling on back button action

具有静态库的 iOS 应用程序总是在启动 Ad Hoc 存档构建时崩溃。无法在 Xcode 调试器中重现