PFObject *object = [[PFObject alloc] initWithClassName:@"Car"];
[object setObject:@"Acura" forKey:@"Make"];
[object setObject:@"TL" forKey:@"Model"];
[object save];
This will create a new object in a "Cars" collection on the Parse dashboard. You can add whatever properties you want, they will be created dynamically for you on the server.
The easiest way to do this is to inherit from PFQueryTableViewController.
@interface FGPhotosViewController : PFQueryTableViewController
@end
@implementation FGPhotosViewController
- (id)init {
self = [super initWithStyle:UITableViewStylePlain className:@"Cars"];
if (self) {
self.objectsPerPage = 30; //enable automatic paging
self.pullToRefreshEnabled = YES;
}
}
- (void)viewDidLoad {
[super viewDidLoad]
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object {
static NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:identifier];
cell.textLabel.font = [UIFont systemFontOfSize:14];
cell.textLabel.textColor = [UIColor colorWithRed:0.7 green:0.5 blue:0.3 alpha:1.0];
}
cell.textLabel.text = [object objectForKey:@"make"];
cell.imageView.file = [object objectForKey:@"model"];
return cell;
}
@end
Images are uploaded using the PFFile class. All you need is an NSData and you can easily save it to Parse:
NSData *imageData = UIImagePNGRepresentation(carImage);
self.imageFile = [PFFile fileWithData:imageData];
[self.imageFile saveInBackground];
Then you can associate this file with a Parse record just like setting any other property:
PFObject *car = [[PFObject alloc] initWithClassName:@"Car"];
[car setObject:self.imageFile forKey:@"photo"];
[car saveInBackgroundWithBlock:^(BOOL success, NSError *error) {
if (success) { ...
} else {
NSLog(@"ERROR: %@", error);
}
}];