Reputation: 1977
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?
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. 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!!
Upvotes: 2
Views: 586
Reputation: 2249
PFUser.CurrentUser gets the user logged in from disk. No need for your async call.
Upvotes: 0
Reputation: 5183
try using findObjectsInBackgroundWithBlock instead of getFirstObjectInBackgroundWithBlock to see if u have data present or not.
It is also pointed here :https://www.parse.com/questions/ios-pfquery-getfirstobjectinbackgroundwithblock-error-when-no-results
Upvotes: 3