解析本地DataStore未显示固定数据

时间:2015-09-21 06:54:42

标签: ios swift parse-platform local-datastore

我已经尝试确保在实现Parse本地数据存储时遵循所有建议的步骤但是固定似乎不起作用或查询固定对象不起作用。我尝试了多种选择。下面是我的视图控制器代码,我也在app委托文件中启用了数据存储区等(使用基本解析启动程序项目)。请告诉我问题出在哪里。

我的控制台输出 - 我能够从解析服务器获取数据但是无法正确固定或正确检索它或其他东西..

 Success 8888 
Optional([])
Push notifications are not supported in the iOS Simulator.
success 7777
Optional([<Restaurant: 0x7f98ca521f60, objectId: 0rRZNCndje, localId: (null)> {
    Name = time;
}])

感谢您的帮助!

import Foundation
import Parse
import ParseUI
import UIKit
import Foundation

class RestaurantAdmin: ViewController {
    func getDataFromLocalDataStore() {
        var userName = PFUser.currentUser()?.username
        var messages2: [AnyObject]!
        var query2: PFQuery = PFQuery(className: "Restaurant")
        query2.fromLocalDatastore()
        query2.whereKey("Owner", equalTo: userName!)
        query2.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
            if (error == nil) {
                messages2 = objects
                println(" Success 8888 ")
                println(objects)
            }
            else {
                println("Fail 8888")
            }
        }
    }

    func refreshRestaurantDataFromServer() {
        var userName = PFUser.currentUser()?.username
        var query = PFQuery(className: "Restaurant")
        query.whereKey("Owner", equalTo: userName!)
        query.selectKeys(["Name"])
        var messages: [AnyObject]!
        query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
            if (error == nil) {
                PFObject.pinAllInBackground(objects, block: nil)
                println("success 7777")
                println(objects)
            }
            else {
                println("error 7777")
            }
        }
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        if (PFUser.currentUser()?.username != nil) {
            refreshRestaurantDataFromServer()
        }
        getDataFromLocalDataStore()
    }
}

1 个答案:

答案 0 :(得分:0)

由于您使用的是query.selectKeys(["Name"]),因此不会下载整个对象。现在您要保存此部分对象,然后使用query2.whereKey("Owner", equalTo: userName!)进行查询。保存的对象不包含"Owner"密钥。