Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Update object by name (Parse)

I have created an object with "DocumentName" and "DocumentContent". I would like the user to be able to update the "DocumentContent" linked with the "DocumentName". Is it possible to do this based on the "DocumentName" or do I have to get the object ID? Thanks for your help.

1 Answer

you could query for the document with that name like so:

PFQuery *query = [PFQuery queryWithClassName:@"Document"];
[query whereKey:@"name" equalTo:@"the document name"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
  if (!error) {
    // The find succeeded.
    NSLog(@"Successfully retrieved %d scores.", objects.count);
    // Do something with the found objects
    for (PFObject *object in objects) {
        NSLog(@"%@", object.objectId);
    }
  } else {
    // Log details of the failure
    NSLog(@"Error: %@ %@", error, [error userInfo]);
  }
}];

and then just assign the object(s) the query finds to a variable and update that variables document content property. the document name might not always be unique though, so the query will find more than one if two documents with the same name exist