从Parse Local Data Store检索信息

时间:2016-12-28 04:01:32

标签: ios swift parse-platform parse-server

我正在尝试从解析本地统计商店检索数据。

我认为它是固定的,因为运行以下内容时没有错误:

let contact = PFObject(className: "temp")
contact["firstName"] = "steve"
contact["lastName"] = "smith"
contact["email"] = "steve.smith@example.com"
contact.pinInBackground()

尝试检索时出现错误:

let query = PFQuery(className: "temp")
query.whereKey("firstName", equalTo: "steve")
query.fromLocalDatastore()

query.findObjectsInBackground { (object, error) in

     if error == nil {
          for object in object! {
               print(object["firstName"] as! String)
          }
     }
}

返回此错误:

  

由于未捕获的异常而终止应用   'NSInternalInconsistencyException',原因:'方法需要固定   启用。“

我在线阅读了

的呼叫位置
Parse.enableLocalDatastore()

在app委托中,但我无法生成任何结果,这个模板是dl直接从解析,这是我的app委托的第一部分:

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


//--------------------------------------
// MARK: - UIApplicationDelegate
//--------------------------------------

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Enable storing and querying data from Local Datastore.
    // Remove this line if you don't want to use Local Datastore features or want to use cachePolicy.

    Parse.enableLocalDatastore()

    let parseConfiguration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in
        ParseMutableClientConfiguration.applicationId = "XXX"
        ParseMutableClientConfiguration.clientKey = "XXX"
        ParseMutableClientConfiguration.server = "XXX"

    })

    Parse.initialize(with: parseConfiguration)

1 个答案:

答案 0 :(得分:0)

...排序

 Parse.enableLocalDatastore()

似乎是我从某个地方获得的遗产项目。

只需添加:

ParseMutableClientConfiguration.isLocalDatastoreEnabled = true

解决了这个问题。

您需要删除或注释掉

的所有实例
Parse.enableLocalDatastore()