Upload
alfonso-alba
View
497
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Presentación NSCoder Madrid Diciembre 2012 Persistencia de datos con Parse.
Citation preview
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);}
Creando y guardando objetos
– save– save:– saveInBackground– saveInBackgroundWithBlock:– saveInBackgroundWithTarget:selector:– saveEventually– saveEventually:
Doc
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]; }); } }]; }}
Creando y guardando de objetos
– delete– delete:– deleteInBackground– deleteInBackgroundWithBlock:– deleteInBackgroundWithTarget:selector:– deleteEventually
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
Relaciones
DocAPI
La demo es muy artesanal
¿Qué herramientas nos da parse?
PFImage
PFImageView *imageView = [[PFImageView alloc] init];imageView.image = [UIImage imageNamed:@"..."]; // placeholder imageimageView.file = (PFFile *)[someObject objectForKey:@"picture"]; // remote image [imageView loadInBackground];
Doc