I am saving a PFObject
called item, into a class called Objects
. So the class is Objects
, and in that class I have a column called item (which are string objects). Every time a row in my tableView
is tapped, the app saves the text of that row to parse.
And if you tap this row 3 times for example, it will save the text 3 different times. Is there a way to only save it once.
Can I use an if statement to check if that string already exists in parse and if so then not save it.
Update:
If I have a class called MenuItem. In MenuItem, I have a string column called item.
Then in my app I have
menuItem[@"item"] = @"item1";
[menuItem saveInBackground];
This code runs every time the app is opened lets say.
How would I check this?
I'm looking at the documentation and I think it is something like this?
PFQuery *query = [PFQuery queryWithClassName:@"MenuItem"];
[query whereKey:@"item" hasPrefix:@""];
[query findObjectsInBackgroundWithBlock:^(NSArray *items, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %lu items.", (unsigned long)items.count);
// Do something with the found objects
for (PFObject *item in items) {
NSLog(@"%@", item.objectId);
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
I am just missing the if statement to check it the item is already there?
Thanks