下面的代码是从parse.com检索的。该代码正常工作,但无法按顺序查询我的数据。有人可以解释为什么吗?
func loadData(){
let findDataParse = PFQuery(className: "JobListing")
findDataParse.whereKey("user", equalTo: PFUser.currentUser()!)
findDataParse.orderByAscending("createdAt")
findDataParse.findObjectsInBackgroundWithBlock{
(objects: [PFObject]?, error: NSError?) -> Void in
if (error == nil) {
for object in objects! {
let userImageFile = object["ImageOne"] as! PFFile
let userImageFile1 = object["ImageTwo"] as! PFFile
let userImageFile2 = object["ImageThree"] as! PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
let listingImage1 = UIImage(data:imageData!)
userImageFile1.getDataInBackgroundWithBlock {
(imageData1: NSData?, error1: NSError?) -> Void in
let listingImage2 = UIImage(data:imageData1!)
userImageFile2.getDataInBackgroundWithBlock {
(imageData2: NSData?, error1: NSError?) -> Void in
let listingImage3 = UIImage(data:imageData2!)
let offers = Information(objectIDParam: object.objectId!, titleOfProjectParam: object["TitleOfProject"] as! String, categoryParam: object["Category"] as! String, viewsParam: object["Views"] as! String, image1Param: listingImage1!, image2Param: listingImage2!, image3Param: listingImage3!)
self.arrayOfOffers.append(offers)
for interests in object["InterestsArray"] as! NSArray{
self.arrayOfInterests.append(interests as! String)
}
self.i++
self.tableView.reloadData()
}}}}}}}
最佳答案
这是我会做的:
创建一个mutableArray
同时提取所有项目request
完成后,将其添加到object
并检查mutableArray
当所有的下载完成排序mutableArray.count == numberOfRequests
这将是更快+易于理解发生了什么事情。
关于ios - 通过创建swift顺序检索解析对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34248176/