ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Persistencia de datos
      con Parse
    aalbagarcia@gmail.com
         @aalbagarcia
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
Creando y guardando
                    objetos

¨C   save
¨C   save:
¨C   saveInBackground
¨C   saveInBackgroundWithBlock:
¨C   saveInBackgroundWithTarget:selector:
¨C   saveEventually
¨C   saveEventually:




                                           Doc
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];
        });
      }
    }];
  }
}
Creando y guardando de
                objetos

¨C   delete
¨C   delete:
¨C   deleteInBackground
¨C   deleteInBackgroundWithBlock:
¨C   deleteInBackgroundWithTarget:selector:
¨C   deleteEventually
Viendo los objetos
Persistencia de datos con Parse
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
Persistencia de datos con Parse
Relaciones




             Doc
             API
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 image
imageView.file = (PFFile *)[someObject objectForKey:@"picture"]; // remote image

[imageView loadInBackground];




                                                                                   Doc

More Related Content

Persistencia de datos con Parse

  • 1. Persistencia de datos con Parse aalbagarcia@gmail.com @aalbagarcia
  • 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 ¨C save ¨C save: ¨C saveInBackground ¨C saveInBackgroundWithBlock: ¨C saveInBackgroundWithTarget:selector: ¨C saveEventually ¨C 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 ¨C delete ¨C delete: ¨C deleteInBackground ¨C deleteInBackgroundWithBlock: ¨C deleteInBackgroundWithTarget:selector: ¨C 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
  • 10. Relaciones 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

Editor's Notes

  • #11: Comentar en la documentaci¨®n c¨®mo se borran los registros