Commits

Alfonso Alba García committed 0487afd

Saving and retrieving groups from parse

Comments (0)

Files changed (2)

ParseTest/PTAppDelegate.m

     [self.window makeKeyAndVisible];
  
  */
-    [Parse setApplicationId:PARSE_APPLICATION_ID
-                  clientKey:PARSE_CLIENT_KEY];
-    PFObject *testObject = [PFObject objectWithClassName:@"TestObject"];
-    [testObject setObject:@"bar" forKey:@"foo"];
-    [testObject save];
+
     [self.window addSubview:[self.tabBarController view]];
     [self.window makeKeyAndVisible];
     return YES;
  
 }
 
+-(void)awakeFromNib
+{
+    [Parse setApplicationId:PARSE_APPLICATION_ID
+                  clientKey:PARSE_CLIENT_KEY];
+}
+
 - (void)applicationWillResignActive:(UIApplication *)application
 {
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

ParseTest/PTGroupsViewController.m

 
 #import "PTGroupsViewController.h"
 #import "PTAddGroupViewController.h"
-
+#import <Parse/Parse.h>
 @interface PTGroupsViewController ()
 
 @end
     return self;
 }
 
-- (void) initializacion
+- (void) initialization
 {
     [self.tableView registerNib:[UINib nibWithNibName:@"StandardTableViewCell" bundle:nil] forCellReuseIdentifier:@"StandardCell"];
-    groups = [NSArray arrayWithObjects:@"grupo1",@"grupo2", nil];
+    [self getGroups];
     self.title = @"Groups";
     self.tabBarItem.image = [UIImage imageNamed:@"groups"];
     UIBarButtonItem *addGroupButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addGroupAction)];
 {
     [super viewDidLoad];
     // Do any additional setup after loading the view from its nib.
-    [self initializacion];
+    [self initialization];
     
     
 }
 - (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"StandardCell" forIndexPath:indexPath];
-    cell.textLabel.text = [groups objectAtIndex:indexPath.row];
+    PFObject *group = [groups objectAtIndex:indexPath.row];
+    cell.textLabel.text = [group objectForKey:@"name"];
     cell.detailTextLabel.text = @"";
     return cell;
 }
 #pragma mark PTGroupDataSourceProtocol
 -(void) addGroup:(NSString *)group
 {
-    NSMutableArray *newGroups = [groups mutableCopy];
-    [newGroups addObject:group];
-    groups = [[NSArray alloc] initWithArray:newGroups];
+    PFObject *newGroup = [PFObject objectWithClassName:@"Group"];
+    [newGroup setObject:group forKey:@"name"];
+    [newGroup save];
+    [self getGroups];
+    NSLog(@"Saving group %@", group);
     [self.tableView reloadData];
+    
+}
+
+#pragma mark Parse Related Functions
+- (void) getGroups
+{
+    PFQuery *query = [PFQuery queryWithClassName:@"Group"];
+    groups = [query findObjects];
 }
 @end