Skip to content

Instantly share code, notes, and snippets.

@mrsidique
Created February 22, 2012 08:13
Show Gist options
  • Select an option

  • Save mrsidique/1883377 to your computer and use it in GitHub Desktop.

Select an option

Save mrsidique/1883377 to your computer and use it in GitHub Desktop.
set card location
for (NSUInteger i = 1; i < myZapCards.count; i++) {
[cardsToQuery addObject:[myZapCards objectAtIndex:i]];
}
PFQuery *query = [PFQuery queryWithClassName:@"cardLocation"];
//[query whereKey:@"card" equalTo:[myZapCards objectAtIndex:zapPageControl.currentPage]];
[query whereKey:@"card" containedIn:cardsToQuery];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d record.", objects.count);
if (objects.count > 0) {
for (PFObject *card in objects) {
//get the ID for the card object
PFObject *objectID = [NSString stringWithFormat:@"%@",[card objectId]];
//set the location of the retrived object to the current location
PFQuery *updateLocation = [PFQuery queryWithClassName:@"cardLocation"];
[updateLocation getObjectInBackgroundWithId:[NSString stringWithFormat:@"%@", objectID] block:^(PFObject *object, NSError *error) {
[object setObject:point forKey:@"location"];
[object saveInBackground];
}];
}
}
else {
for (NSUInteger i = 0; i < cardsToQuery.count; i++) {
PFObject *currentLocation = [PFObject objectWithClassName:@"cardLocation"];
[currentLocation setObject:[cardsToQuery objectAtIndex:i] forKey:@"card"];
[currentLocation setObject:point forKey:@"location"];
[currentLocation saveInBackground];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment