Persistencia de datos con Parse

Post on 13-Jun-2015

499 views 1 download

Tags:

description

Presentación NSCoder Madrid Diciembre 2012 Persistencia de datos con Parse.

Transcript of Persistencia de datos con Parse

Persistencia de datos con Parse

aalbagarcia@gmail.com@aalbagarcia

Creando y guardando objetos

Doc

#pragma mark PTGroupDataSourceProtocol-(void) addGroup:(NSString *)group{ PFObject *newGroup = [PFObject objectWithClassName:@"Group"]; [newGroup setObject:group forKey:@"name"]; [newGroup saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if(succeeded) { dispatch_async(dispatch_get_main_queue(), ^{ [self getGroupsAndReloadDataInBackground]; }); } }]; NSLog(@"Saving group %@", group);}

Borrando objetos

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete) { PFObject *group = [groups objectAtIndex:indexPath.row]; [group deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if(succeeded & !error) { NSMutableArray *newGroups = [groups mutableCopy]; [newGroups removeObjectAtIndex:indexPath.row]; groups = [newGroups copy]; dispatch_async(dispatch_get_main_queue(), ^{ [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; }); } }]; }}

Viendo los objetos

Relaciones- (void) addPerson:(NSDictionary *)data{ PFObject *group = [data objectForKey:@"group"]; PFObject *person = [PFObject objectWithClassName:@"Person"]; [person setObject:[data objectForKey:@"firstName"] forKey:@"firstName"]; [person setObject:[data objectForKey:@"lastName"] forKey:@"lastName"]; [person setObject:[data objectForKey:@"email"] forKey:@"email"]; [person setObject:[data objectForKey:@"twitter"] forKey:@"twitter"]; PFRelation *memberOf = [person relationforKey:@"memberOf"]; [memberOf addObject:group]; [person saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if(succeeded) { dispatch_async(dispatch_get_main_queue(), ^{ [self loadDataInBackground]; }); //We cannot create the inverse relation until the object is saved PFRelation *relation = [group relationforKey:@"members"]; [relation addObject:person]; [group saveInBackground]; } else { NSLog(@"Person could not be saved."); } }];}

DocAPI

La demo es muy artesanal

¿Qué herramientas nos da parse?

PFLoginViewController

Doc

PGSignUpViewController

Doc

PFQueryTableViewController

Doc

PFImage

PFImageView *imageView = [[PFImageView alloc] init];imageView.image = [UIImage imageNamed:@"..."]; // placeholder imageimageView.file = (PFFile *)[someObject objectForKey:@"picture"]; // remote image     [imageView loadInBackground];

Doc