在后台

时间:2017-08-11 13:26:48

标签: ios swift parse-platform

我有一个应用程序,它从Parse服务器获取数据。以下是我用来浏览"提供"中的所有行的代码。类并将它们存储在offerList数组中。一切都按预期工作,但我一直在

warnBlockingOperationOnMainThread() 
Xcode中的

警告。调用整个功能或其内部

DispatchQueue.global().async

也没有帮助。这是实际的功能:

func parseOfferList(){
    var amount: Int = 0
    offerList.removeAll()
    let offerQuery = PFQuery(className: "Offer")
    offerQuery.countObjectsInBackground { (count, error) in
        if error == nil {
            amount = Int(count)

            for i in 1...amount-1{
                let offerObj = try! offerQuery.whereKey("ID", equalTo: i).getFirstObject()
                var tempOffer = Offer()
                tempOffer.id = offerObj.object(forKey: "ID") as! Int
                tempOffer.name = offerObj.object(forKey: "name") as! String
                tempOffer.desc = offerObj.object(forKey: "desc") as! String
                tempOffer.lowSale = offerObj.object(forKey: "lowSale") as! Int
                tempOffer.topSale = offerObj.object(forKey: "topSale") as! Int

            offerList.append(tempOffer)
            }
        }
    }
}

我想在应用启动时立即运行此功能,因此当用户登录时,offerList已经填充了信息。有没有办法实现这个目标?

0 个答案:

没有答案