5
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    // Set up the Parse SDK
    let configuration = ParseClientConfiguration {
        $0.applicationId = "WhatsTheHW"
        $0.server = "https://whatsthehw-parse-alan.herokuapp.com/parse"
    }
    Parse.initializeWithConfiguration(configuration)

    let query = PFQuery(className: "Course")

    query.findObjectsInBackgroundWithBlock {(result: [PFObject]?, error: NSError?) -> Void in
        for object in result! {
            // existing objectIds: 1Ja2Hx77zA, 34AF1vKO6f, 5FWlsswxw0
            if object.objectId == "34AF1vKO6f" {
                object["studentRelation"] = ["hi", "ih"]
                object.saveInBackgroundWithBlock{(success, error) in
                    if success == true {
                        print("\(object) saved to parse")
                    } else {
                        print("save failed: \(error)")
                    }
                }
            }
        }
    }

    return true
}

This is the minimum I can reduce this task to (this code is at AppDelegate).

It all worked fine when I tried using REST api and api console in parse dashboard but it doesn't work with iOS sdk.

The error I'm getting from the print statement is

Error Domain=Parse Code=101 "Object not found." UserInfo={code=101, temporary=0, error=Object not found., NSLocalizedDescription=Object not found.}

It works if I'm simply adding a new object like this :

let object = PFObject(className: "Course")
object["name"] = "German"
object["studentRelation"] = ["a", "b"]

object.saveInBackgroundWithBlock{(success, error) in
    if success == true {
        print("save completed")
        print("\(object) saved to parse")
    } else {
        print("save failed: \(error)")
    }
}

I'm really lost and I don't know why this is happening.

Thanks in advance.

2
  • Parse will be EOL on 1/28/17. I suggest you use this error as a starting point and force your hand, if you will, to move to another BaaS. Commented Aug 6, 2016 at 1:53
  • 2
    Hi @TheValyreanGroup. parse.com will be EOL but parse-server not :) and Alan is using parse-server and not parse.com. parse-server is the open source platform that was released by parse.com team. you can read it here: github.com/ParsePlatform/parse-server Commented Aug 6, 2016 at 18:17

2 Answers 2

3

This issue might relate to the access rights (ACL) of the object that you're trying to save. [Error]: Object not found is printed when a user that doesn't have write access to an object tries to save it, the error message of the Parse SDK is really misleading here!

Make sure the parse user who is trying to save the object has the proper writes to actually write on that object in your parse DB.

An easy fix will be to set the default ACL inside your app to public read + write:

let acl = PFACL()
acl.publicReadAccess = true
acl.publicWriteAccess = true
PFACL.setDefaultACL(acl, withAccessForCurrentUser: true)

Be careful with this approach though, usually you want to set access rights according to the actual role of the user. So a better alternative would be to only set the ACL on the PFObject when you're creating it and only give write access to the users you know should be able to alter the object.

Sign up to request clarification or add additional context in comments.

Comments

0

can you please first find your object, save into another object and run the saveInBackground outside of the loop.

Your code should look like the following:

    var objectToSave : PFObject?

    let query = PFQuery(className: "Course")
    query.findObjectsInBackgroundWithBlock {(result: [PFObject]?, error: NSError?) -> Void in
        for object in result! {
            if object.objectId == "jMIxdSXNRH" {
                objectToSave = object
            }
        }


        if objectToSave != nil {
            objectToSave!["studentRelation"] = ["hi", "ih"]
            objectToSave!.saveInBackgroundWithBlock{(success, error) in
                if success == true {
                    print("\(objectToSave) saved to parse")
                } else {
                    print("save failed: \(error)")
                }
            }
        }

    }

I am using my objectId's and not your so please change them to yours :)

1 Comment

I have tried your suggestion but it still returns the same error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.