【问题标题】:Retrieve values out of PFObject从 PFObject 中检索值
【发布时间】:2015-06-06 18:53:29
【问题描述】:

我有一个保存按钮,可以在 Parse 中将分数和玩家名称保存到 GameScore。当我从 Parse 加载 GameScore 时,我想将加载的值设置为变量“score”。这不起作用,谁能告诉我我做错了什么? 谢谢

示例:让 score = gameScore["score"] as Int

// Load button tapped
@IBAction func loadButtonTapped(sender: UIButton) {

    var query = PFQuery(className:"GameScore")
    query.getObjectInBackgroundWithId("F1efANYzOE") {
        (gameScore: PFObject?, error: NSError?) -> Void in
        if error == nil && gameScore != nil {
            println(gameScore)
            let score = gameScore["score"] as Int

        } else {
            println(error)
        }
    }
}

}

【问题讨论】:

  • 你能说出你遇到了什么错误吗??
  • 我并没有完全得到错误。但它不会将分数变量设置为我加载的值,女巫就是我想要它做的。
  • 你的语句 println(gameScore) 的输出是什么,它打印了什么吗??
  • Optional( { playerName = Name; score = 1353; }) 我希望它将“score”变量设置为 1353已加载。
  • 如果在 let score = gameScore['score'] 之后打印 score 变量会得到什么?

标签: ios swift parse-platform


【解决方案1】:

尝试使用以下代码从特定列中检索特定数据。您必须在下面的代码中输入您的对象名称、对象 ID 和列名称并运行它。它会起作用的。

let query = PFQuery(className:"Your Object name")

        query.getObjectInBackgroundWithId("Your Object ID") {
            (gameScore: PFObject?, error: NSError?) -> Void in

            if error == nil  {
                print(gameScore!.objectForKey("your column name") as! String)
            } else {
                print(error)
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-10
    • 2011-10-02
    • 2013-08-14
    相关资源
    最近更新 更多