我的类在解析时设置了字符串,如何将它们下拉到数组中。
我目前没有自己的代码。我已经找到了php或php中的内容,但无法迅速找到任何内容。
var query = PFQuery(className:"GameScore")
query.getObjectInBackgroundWithId("xWMyZEGZ") {
(gameScore: PFObject!, error: NSError!) -> Void in
if error == nil && gameScore != nil {
println(gameScore)
} else {
println(error)
}
}
我不这么认为,因为那只是在检索对象。
简而言之,有没有办法采用Class> String并将列中的所有数据放入.swift中的数组中?
最佳答案
您将如何处理阵列?由于您将在gameScore对象中找到所有可用数据,因此您可以从那里进行任何操作。
var query = PFQuery(className:"GameScore")
query.getObjectInBackgroundWithId("xWMyZEGZ") {
(gameScore: PFObject!, error: NSError!) -> Void in
if error == nil && gameScore != nil {
println(gameScore)
for singleScore in gameScore{
println(singleScore) // this is the single result
println(singleScore.objectId)
println(singleScore["anyColName"])
}
} else {
println(error.userInfo) // returns more details
}
}
关于您的问题:
var myArray: NSMutableArray! = NSMutableArray()
var query = PFQuery(className:"GameScore")
query.getObjectInBackgroundWithId("xWMyZEGZ") {
(gameScore: PFObject!, error: NSError!) -> Void in
if error == nil && gameScore != nil {
println(gameScore)
var temp: NSArray = gameScore as NSArray
self.myArray = temp.mutableCopy() as NSMutableArray // now you have all results in an array
} else {
println(error.userInfo)
}
}