Parse.com如何获取所有用户的相关数据

时间:2015-11-24 16:58:32

标签: ios macos parse-platform swift2

我有一个应用程序,我试图加载用户及其所有相关数据。在关系中,我将BodyTracking作为一种关系。另一个是DiaryWeek,而DiaryDays则是本周的DiaryDays。 我成功地完成了所有的BodyTracking,但是当我为DiaryWeeks尝试相同的时候,我得到一个错误,说我必须等待。我猜想发生的事情是BodyTracking,它是用'findObjectsInBackgroundWithBlock'当DiaryWeek请求被调用时,它仍在继续。 有没有办法一次性提取所有数据?

        // Body Tracking
    bodyEntries.removeAll()
    let trackingQuery = PFQuery(className: "BodyTracking")
    trackingQuery.whereKey("user", equalTo: member)
    trackingQuery.orderByDescending("trackingDate")
    trackingQuery.findObjectsInBackgroundWithBlock {
        (objects: [PFObject]?, error: NSError?) -> Void in

        if error == nil {
            print("Successfully retrieved \(objects!.count) body entries.")

            if let objects = objects! as? [PFObject] {
                for object in objects {
                    let bodyEntry = BodyTracking(object: object)
                    self.bodyEntries.append(bodyEntry)
                }
                self.bodyTrackingTableView.reloadData()
            }
        } else {
            // Log details of the failure
            print("Error: \(error!) \(error!.userInfo)")
        }
    }

    // Food Diary
    foodWeeks.removeAll()
    let diaryQuery = PFQuery(className: "FoodDiaryWeek")
    diaryQuery.whereKey("user", equalTo: member)
    diaryQuery.orderByDescending("weekStartDate")
    trackingQuery.findObjectsInBackgroundWithBlock {
        (objects: [PFObject]?, error: NSError?) -> Void in

        if error == nil {
            print("Successfully retrieved \(objects!.count) food weeks")

            if let objects = objects! as? [PFObject] {
                for object in objects {
                    let foodWeek = FoodDiaryWeek(object: object)
                    self.foodWeeks.append(foodWeek)
                }
            }
        } else {
            // Log details of the failure
            print("Error: \(error!) \(error!.userInfo)")
        }
    }

错误消息:此查询具有出色的网络连接。你必须等到它完成。

1 个答案:

答案 0 :(得分:0)

看起来你不小心执行了trackingQuery两次。永远不会执行diaryQuery。可能是复制/粘贴错误(?)

   // Food Diary
foodWeeks.removeAll()
let diaryQuery = PFQuery(className: "FoodDiaryWeek")
diaryQuery.whereKey("user", equalTo: member)
diaryQuery.orderByDescending("weekStartDate")
**trackingQuery**.findObjectsInBackgroundWithBlock {

用diaryQuery替换trackingQuery