Swift错误地阅读PFQuery Return

时间:2017-04-24 00:07:26

标签: ios parse-platform swift2 parse-server pfquery

我在Swift中有PFQuery函数,它应该根据返回的对象进行操作。我试过如果错误== nil,如果对象!= nil,如果错误== nil&&对象!= nil,但它总是表现为键" otherUser"并且"回复了#34;对于查询的要求是相同的,尽管" otherUser"没有在课程中找到"请求"并且"回复了#34;等于" False"。 (我缩短了实际的全长查询,因为它太长了。)

let query = PFQuery(className: "Requests")
        query.whereKey("otherUser", equalTo: PFUser.currentUser()!.objectForKey("username") as! String)
        query.whereKey("responded", equalTo: "True")
        query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
            if error == nil && objects != nil{
                print(objects)
                print("disabling confirm button")
                self.stopTime = self.defaults.integerForKey("intKey")
            }else{
                print("Did not respond yet.")
                self.counter = 1200
                self.storyboard
            }
        })
}

1 个答案:

答案 0 :(得分:0)

即使找不到<script src="http://ajax.googleapis.com/ajax/libs/jQuery/1.11.1/jQuery.min.js"></script> <script> $(document).ready(function(){ var x = $("div#demo").text(); if(x == "abc"){ $(this).closest("td").removeClass("old"); $(this).closest("td").addClass("new"); } }); </script> <h:body> <table cellspacing="10"> <tr> <td class="old"> <h:dataTable value="#{bean.fonk()}" var="myvar" rows="1" first="0"> <h:column>#{bean.surname} <div id="demo" style="visibility: visible">#{myvar.name}</div> </h:column> </h:dataTable> </td> <td class="old"> <h:dataTable value="#{bean.fonk()}" var="myvar" rows="1" first="1"> <h:column>#{bean.surname} <div id="demo" style="visibility: visible">#{myvar.name}</div> </h:column> </h:dataTable> </td> <td class="old"> <h:dataTable value="#{bean.fonk()}" var="myvar" rows="1" first="2"> <h:column>#{bean.surname} <div id="demo" style="visibility: visible">#{myvar.name}</div> </h:column> </h:dataTable> </td> <td class="old"> <h:dataTable value="#{bean.fonk()}" var="myvar" rows="1" first="3"> <h:column>#{bean.surname} <div id="demo" style="visibility: visible">#{myvar.name}</div> </h:column> </h:dataTable> </td> </tr> </table> <table cellspacing="10"> <tr> <td class="old"> <h:dataTable value="#{bean.fonk()}" var="myvar" rows="1" first="4"> <h:column>#{bean.surname} <div id="demo" style="visibility: visible">#{myvar.name}</div> </h:column> </h:dataTable> </td> </h:body> otherUser为假,responded仍然不会返回错误,query只会是一个空数组。并且一个空数组不是nil,它存在于堆中。

因此,只要您正在做正确的事情,即使查询与您的约束不匹配,它仍然会返回一个空数组而不是错误。

如果要检查查询是否返回了任何结果,可以使用objects检查返回的结果是否为空。