简体   繁体   English

Swift Parse-方法不会停止执行

[英]Swift Parse - Method doesn't stop executing

I have the following code which basically would query Parse class and return a result set. 我有以下代码,基本上可以查询Parse类并返回结果集。 After returning the results, I would pass that array to a function to check if some elements are set or not. 返回结果后,我将该数组传递给函数以检查是否设置了某些元素。

I used print statements all over the code to try and debug, and found that query executes and within the 我在整个代码中使用了print语句进行尝试和调试,发现该查询在

if error == nil

I am getting the results array to be empty. 我正在结果数组为空。 Hence when I pass that to my function below, it never gets out of it: 因此,当我将其传递给下面的函数时,它永远不会消失:

func emailOrUsernameIsTaken(results: [PFObject])->Int
    {
        /*Check if username is taken or if email is taken*/

        var preferenceTaken: Int = 0

        if(results[0]["email"] as! String != "" && results[0]["email"] as! String == self.userObject.email!)
        {
            preferenceTaken = 1
        }else if(results[0]["appUsername"] as! String != "" && results[0]["appUsername"] as! String == self.userObject.username!){
            preferenceTaken = 2
        }

        return preferenceTaken
    }

and this is the code where the query is taking place: 这是执行查询的代码:

let query = PFQuery.orQueryWithSubqueries([usernameInputCheck, emailInputCheck])
        query.findObjectsInBackgroundWithBlock {
            (results: [PFObject]?, error: NSError?) -> Void in
            if error == nil {
                print("Before")
                let checkResult = self.emailOrUsernameIsTaken(results!)
                print(results)
                print("After")
            }
        }

as an output from print statements above, I get in console: 作为上述打印语句的输出,我进入控制台:

Before
Optional([])
After

Can someone help me to find out the issue. 有人可以帮我找出问题所在吗? I am surprised why this is not working. 我很惊讶为什么这不起作用。

If results is empty, results[0]["email"] as! String 如果results为空,则results[0]["email"] as! String results[0]["email"] as! String should crash because you are force unwrapping a nil optional value. results[0]["email"] as! String应该崩溃,因为您强制拆开nil可选值。 So the story you are telling is not consistent. 因此,您讲的故事并不一致。

If the actual problem is the empty results - you would have to provide details about your queries and why you expect there to be a populated result. 如果实际问题是空的结果-您将必须提供有关查询的详细信息以及为什么期望填充结果。

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

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