Persistencia de datos con Parse

705 views
593 views

Published on

Presentación NSCoder Madrid Diciembre 2012

Persistencia de datos con Parse.

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
705
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Comentar en la documentación cómo se borran los registros
  • Persistencia de datos con Parse

    1. 1. Persistencia de datos con Parse aalbagarcia@gmail.com @aalbagarcia
    2. 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. 3. Creando y guardando objetos– save– save:– saveInBackground– saveInBackgroundWithBlock:– saveInBackgroundWithTarget:selector:– saveEventually– saveEventually: Doc
    4. 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. 5. Creando y guardando de objetos– delete– delete:– deleteInBackground– deleteInBackgroundWithBlock:– deleteInBackgroundWithTarget:selector:– deleteEventually
    6. 6. Viendo los objetos
    7. 7. 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
    8. 8. Relaciones Doc API
    9. 9. La demo es muy artesanal¿Qué herramientas nos da parse?
    10. 10. PFLoginViewController Doc
    11. 11. PGSignUpViewController Doc
    12. 12. PFQueryTableViewController Doc
    13. 13. PFImagePFImageView *imageView = [[PFImageView alloc] init];imageView.image = [UIImage imageNamed:@"..."]; // placeholder imageimageView.file = (PFFile *)[someObject objectForKey:@"picture"]; // remote image[imageView loadInBackground]; Doc

    ×