简体   繁体   English

ios快速解析:没有结果与查询匹配

[英]ios swift parse: no results matched the query

I pin username and password to the local datastore and on app start I want to check if its available. 我将用户名和密码固定到本地数据存储区,在应用启动时,我想检查其是否可用。 Therefore I do a 因此,我做了一个

var query = PFQuery(className:"LocalUser")
    query.fromLocalDatastore()
    query.whereKeyExists("username")
    query.getFirstObjectInBackgroundWithBlock {
        (object: PFObject!, error: NSError!) -> Void in
        if error == nil {....

When I run the app, I get the error: no results matched the query 运行应用程序时,出现错误:没有结果与查询匹配

Why do I get this as error? 为什么我得到这个错误? Why can I not handle a "nothing found" in the }else{ Statement? 为什么我不能处理} else {语句中的“未找到内容”?

I mean, a empty result is not so unusual? 我的意思是,空结果不是那么不寻常吗?

What I want to achieve, is that no local user data was found, send the user to the login viewController. 我要实现的是,找不到本地用户数据,将用户发送到登录viewController。 But as long as I get this kind of error I can't do that. 但是,只要出现这种错误,我就无法做到。

Is there maybe another way to check if local store data exists? 也许还有另一种方法来检查本地存储数据是否存在?

Thanks!! 谢谢!!

try using findObjectsInBackgroundWithBlock instead of getFirstObjectInBackgroundWithBlock to see if u have data present or not. 尝试使用findObjectsInBackgroundWithBlock代替getFirstObjectInBackgroundWithBlock来查看您是否有数据。

It is also pointed here : https://www.parse.com/questions/ios-pfquery-getfirstobjectinbackgroundwithblock-error-when-no-results 它也指向这里: https : //www.parse.com/questions/ios-pfquery-getfirstobjectinbackgroundwithblock-error-when-no-results

PFUser.CurrentUser gets the user logged in from disk. PFUser.CurrentUser获取从磁盘登录的用户。 No need for your async call. 无需您的异步调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM