Mais conteúdo relacionado
Semelhante a Persistencia de datos con Parse (20)
Persistencia de datos con Parse
- 2. Creando y guardando
objetos
#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);
}
Doc
- 3. Creando y guardando
objetos
– save
– save:
– saveInBackground
– saveInBackgroundWithBlock:
– saveInBackgroundWithTarget:selector:
– saveEventually
– saveEventually:
Doc
- 4. Borrando objetos
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath
{
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];
});
}
}];
}
}
- 5. Creando y guardando de
objetos
– delete
– delete:
– deleteInBackground
– deleteInBackgroundWithBlock:
– deleteInBackgroundWithTarget:selector:
– deleteEventually
- 8. 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.");
Doc
}
}]; API
- 11. La demo es muy artesanal
¿Qué herramientas nos da parse?
- 15. PFImage
PFImageView *imageView = [[PFImageView alloc] init];
imageView.image = [UIImage imageNamed:@"..."]; // placeholder image
imageView.file = (PFFile *)[someObject objectForKey:@"picture"]; // remote image
[imageView loadInBackground];
Doc
Notas do Editor
- Comentar en la documentación cómo se borran los registros