Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从parse.com获取数据时返回nil_Ios_Swift_Parse Platform_Null - Fatal编程技术网

Ios 从parse.com获取数据时返回nil

Ios 从parse.com获取数据时返回nil,ios,swift,parse-platform,null,Ios,Swift,Parse Platform,Null,我想从我的解析类中检索数据。我想把它们保存在字符串中。这是我的密码: var query = PFQuery(className:"Tags") query.getObjectInBackgroundWithId("IsRTwW1dHY") { (gameScore2: PFObject?, error: NSError?) -> Void in if error == nil && gameS

我想从我的解析类中检索数据。我想把它们保存在字符串中。这是我的密码:

        var query = PFQuery(className:"Tags")
        query.getObjectInBackgroundWithId("IsRTwW1dHY") {
            (gameScore2: PFObject?, error: NSError?) -> Void in
            if error == nil && gameScore2 != nil {

                let username = self.gameScore2["username"] as? String
                let tagtext = self.gameScore2["tagtext"] as? String

                println(username)
                println(tagtext)

                println(gameScore2)

            } else {

                println(error)

            }
    }
现在我的问题是字符串“username”和“tagtext”为零,但记录不是空的,因为在
println(gameScore2)
部分中,我要取回内容。在这部分代码之后,我的控制台如下所示:


如何从parse.com获取字符串中的数据?

在我看来,您有两个变量“gameScore2”,一个是通过self.gameScore2访问的实例变量,另一个是作为完成块参数的参数gameScore2。(使用Swift术语,完成关闭。)

您应该避免在不同级别的作用域中使用相同的变量名,因为这样会导致混淆


将块参数重命名为类似于
tagsResult
的名称,并将块中的所有代码更改为使用该新名称而不是self.gameScore2。

此参数的可能重复项也不是重复项!是的,此名称有问题,它现在与此块中所有代码的名称tagResult一起工作。永远不要在范围的外部级别和内部级别中使用相同的变量名称。这是一个肯定火的方式,创造错误,将驱动你疯狂。(该路径导致疯狂!)是的,我不清楚是否有两个相同的变量名。每当您编写使用当前类实例变量变量的块代码时,它会阻止您并使您添加显式的“self”前缀。这应该会在你的头脑中敲响警钟。(除非必须使用self,否则不要使用self。Swift通常可以推断您正在从上下文引用实例变量,并且必须对self explicit进行块引用,这有助于您了解发生了什么。这是一个非常有用的技巧!