gpt4 book ai didi

ios - 从 Parse.com 查询数组到数组

转载 作者:行者123 更新时间:2023-11-29 01:29:05 26 4
gpt4 key购买 nike

我正在尝试从 Parse.com 查询一个空数组。

我的空数组:

var commentsArray = [NSArray]()

我的查询代码:

var query1 = PFQuery(className: "currentUploads")
query1.whereKey("objectId", equalTo: "ImxZwVx7L8")
query1.findObjectsInBackgroundWithBlock{
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {

//For each object in the class object, append it to myArray
if let dataArray = object["comments"] as? NSArray {
self.commentsArray.append(dataArray)

println("codeBelow")
println(self.commentsArray)
println(self.commentsArray.count)
}
}
}
} else {
println("\(error?.userInfo)")
}
}

在输出中我得到这个:

codeBelow
[(
abc,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
def,
tdrthdrthdrthdrthdrhtrthdrthdrthdrthdrthdrthdrthdrthdrth,
"jdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrthdrt dhrt hdrthdrthdrthdrh 5hsr5d r5hdr5h drthr t hdrt hkl"
)]
1

如您所见,输出计数为 1,但它应该为 38。如果我执行 println(dataArray.count),它会为我输出 38。怎么会这样?怎么了?

最佳答案

首先,创建一个空数组:

var commentsArray: [String] = [String]()

现在查询:

var query = PFQuery(className:"currentUploads")
query.whereKey("objectId", equalTo:"ImxZwVx7L8")
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {
var list: AnyObject? = object.objectForKey("comments")
self.commentsArray = list! as! NSArray as! [String]
self.tableView.reloadData()
}

}
} else {
println("\(error?.userInfo)")
}
}

关于ios - 从 Parse.com 查询数组到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33660394/

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