Parse local datastore doesn't work - Swift 2

553 views Asked by At

I am currently using the latest version of Parse 1.14.2 and Bolts 1.8.4.Parse is implemented correctly and I have been using it for a long time now. The problem I'm facing now is when I try to use Parse's local datastore. I have the following code in my AppDelegate.swift:

Parse.enableLocalDatastore()
                Parse.setApplicationId("ID",
                clientKey: "Client_Key")

I have the following code to create and save a string named firstName in a class named contact:

let contact = PFObject(className: "contact")
                        contact["firstName"] = "Jack"
                        contact.pinInBackground()

Here is the code to retrieve objects from the created class:

                            let query = PFQuery(className: "contact")
                        query.fromLocalDatastore()
                        query.getFirstObjectInBackgroundWithBlock({ (object, error) -> Void in
                            if error == nil {
                                if let contact = object {
                                    print(contact.objectForKey("firstName"))

                                }
                            }
                        })

I have added libsqlite3.dylib to my project. My app doesn't crash when I run this code but it simply gives me the following message when I try to retrieve objects:

    2016-08-29 11:31:38.049 App_Demo[14436:3504319] [Bolts] Warning: `BFTask` caught an exception in the continuation block. 
This behavior is discouraged and will be removed in a future release. 
Caught Exception: Method requires Pinning enabled.

Can anyone help me to work around this issue? I am guessing the issue is that this version of Bolts cannot pin Parse objects in the background and I need to work my way around this bug. Any help would be appreciated as I have been stuck at this for a while and can't find too much info online.

Edited: I have tried downgrading Bolts, but then Parse downgrades with it in Cocoapod and it causes errors in Xcode.

1

There are 1 answers

0
user2867432 On

it's not objectforkey. You need to call object["UsedName"] "UsedName" being the key. Hope that helps.