gpt4 book ai didi

ios - PFQuery 完成后开始一些事情

转载 作者:行者123 更新时间:2023-11-30 13:48:26 24 4
gpt4 key购买 nike

查询完成后是否可以执行某些操作?我有一个查询对象的 PFQuery,这些对象的 objectId 将附加到一个数组中。 materUserObjects 是一个 PFUser,MatesIdsAndNames 是一个字典,其余的都是 String `func queryNow(){

    if mateUserObject.isEmpty == false{

for mateId in mateUserObject{



let date = NSDate()
let dateInt = date.timeIntervalSince1970

let query = PFQuery(className: "calendarEvents")
query.whereKey("createdBy", equalTo: mateId)
query.whereKey("StartDate", lessThan: dateInt)
query.whereKey("EndDate", greaterThan: dateInt)
query.cachePolicy = .NetworkOnly
query.findObjectsInBackgroundWithBlock({ (objects:[PFObject]?, error:NSError?) -> Void in

if error != nil{
print(error)
}else{

if objects?.isEmpty == true{
self.freeMateIds.append(mateId.objectId!)
print(self.freeMateIds)
if self.mateUserObject.last == mateId{


if self.freeMateIds.isEmpty == false{


for freeMate in self.freeMateIds{

let oneFreeMate = self.matesIdsAndNames[freeMate]
self.freeMateNames.append(oneFreeMate!)
print(self.freeMateNames)
}

}
self.MatesTableView.reloadData()

}

}

}


})



}


}


}`

最佳答案

你使用query.findObjectInBackgroundWithBlock吗?如果是,我建议您使用竞争处理程序:

typealias CompletionHandler = (success: Bool) -> Void

// Ajoute dans le tableau _applications les applications stockées sur Parse
func fetchData(completionHandler: CompletionHandler) {
let query = PFQuery(className: "Test")
var supposeObjectCount: Int = 0
var objectCount: Int = 0

// Ajoute un filtre pour la requete
query.orderByAscending("Id")

// Trouve les objets sur Parse
query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error: NSError?) -> Void in

// S'il n'y a pas d'erreur
if error == nil {

supposeObjectCount = objects!.count


if let objects = objects {


for object in objects {

// ..

if(supposeObjectCount == ++objectCount) {
completionHandler(success: true)
}
}

}
}

else {
print("Error")
}
}
}



// Call the function

func test() {
fetchData({ (success) -> Void in


if success {
// Executed when query is completed
}
})
}

希望这有帮助!

关于ios - PFQuery 完成后开始一些事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34624777/

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