Object update in Parse iOS, [Error]: object not found

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 (this code is in AppDelegate).

Everything worked fine when I tried using the REST api and api console in the parsing panel, but it does not work with iOS sdk.

The error I get 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 just add a new object as follows:

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 am really lost, and I do not know why this is happening.

Thanks in advance.

+4
source share
2 answers

(ACL) , . [Error]: Object not found , , write, , Parse SDK !

, , , .

, ACL public read + write:

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

, . ACL PFObject write , , , .

+2

, saveInBackground .

:

    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)")
                }
            }
        }

    }

objectId, , , , .:)

0

Source: https://habr.com/ru/post/1650376/


All Articles