Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Stone Preston
42,016 PointsPFRelation with PFFile objects
Im trying to create a relation that contains PFFile objects. Im getting an error when I try to do this the error is -[PFFile parseClassName]: unrecognized selector sent to instance 0x170479cc0'. I also got a warning that sending PFFile was incompatible with PFObject, though I thought PFFile inherited from PFObject. I tried casting my PFFile object to PFObject, but still get the same error. Any thoughts on this? Amit Bijlani
here is my code. the file objects have already been saved to parse before saving the newspot object
[newSpot saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(!error) {
PFRelation *imageRelation = [newSpot relationforKey:@[Ben Jakuben](https://teamtreehouse.com/bendog24) "hasImages"];
[imageRelation addObject:file];
PFRelation *thumbnailRelation = [newSpot relationforKey:@"hasThumbnails"];
[thumbnailRelation addObject:(PFObject *)thumbnailFile];
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"An error occurred" message:@"Please try adding the spot again" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
}
3 Answers
Stone Preston
42,016 Pointsfigured it out
PFObject *photo = [PFObject objectWithClassName:@"Photo"];
photo[@"image"] = file;
photo[@"thumbnail"] = thumbnailFile;
[photo saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
//photo was saved successfully
if (!error) {
//successful save of photo objext
//continue uploading the rest of the spot object
//create the photo relation
PFRelation *photoRelation = [newSpot relationforKey:@"hasPhotos"];
[photoRelation addObject:photo];
Stone Preston
42,016 Pointstagging Ben Jakuben as well
Amit Bijlani
Treehouse Guest TeacherPFFile inherits from NSObject not PFObject. See: https://parse.com/docs/ios/api/Classes/PFFile.html
Stone Preston
42,016 Pointsahh. well I think im going to try just creating a new Photo object, add my files to that object, save it, then add a relation that contains that photo object instead of the files directly. I think that would work.