gpt4 book ai didi

ios - 将 parse 中的数据保存为字符串

转载 作者:行者123 更新时间:2023-11-28 07:06:55 25 4
gpt4 key购买 nike

我想将解析类中的数据保存到字符串中。我实际上使用以下代码从我的解析类中检索数据。

@IBAction func readAction(sender: UIButton) {

var tagAutor = ""
var tagText = ""

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

// tagAutor = tag["username"]
// tagText = tag["tagtext"]

} else {
println(error)
}
}
}

在评论中有我想要做的,在我名为“Tags”的类中有两个名为“username”和“tagtext”的列我想将它们保存在两个字符串变量“tagAutor”和“tagText”中. println(tag) 打印出以下内容:

My console output

如何将查询中的对象保存到这两个字符串变量中?

最佳答案

告诉编译器将 AnyObject 转换为 String:

if let author = tag["username"] as String {
tagAutor = author
}

并且可能移动 tagAuthor 的定义,以便您可以在函数外使用 I

关于ios - 将 parse 中的数据保存为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30175263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com