0
votes

I getting this error "PFObject values may not have class: PFFile" when I try to save a image on a Parse object...

This is the code and the Object:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"GGB" ofType:@"jpg"];
    NSData *d = [NSData dataWithContentsOfFile:path];
    PFFile *f = [PFFile fileWithName:[NSString stringWithFormat:@"f_%d_%d.jpg",ctIdx,chIdx] data:d];

    GPChallenge *ch = GPChallenge.object;
    ch.name = [NSString stringWithFormat:@"Challenge %d.%d",(chIdx+1),(ctIdx+1)];
    ch.category = cat;
    ch.image = f;

    [f save];
    [ch save];

-- GPChallenge.h

#import <Parse/Parse.h>

@class GPCategory;

@interface GPChallenge : PFObject<PFSubclassing>
+ (NSString *)parseClassName;

@property NSString *name;
@property GPCategory *category;
@property PFFile *image;
@end

-- GPChallenge.m

#import "GPChallenge.h"
#import <Parse/PFObject+Subclass.h>

@implementation GPChallenge

@dynamic name;
@dynamic category;
@dynamic image;

+(void)load {
    [self registerSubclass];
}

+ (NSString *)parseClassName {
    return @"Challenge";
}

@end

Any idea?

1
Thanks Fabio, but is not the same problem, I'm already using PFFile.Laullon
Yes you are, but you can't allocate it like you are... You need to pass it like an UIimage before do the PFFile.Fabio Cardoso
no, that wasn't the problem because the same code works on the app, I forgot to mention that the problem is when the code runs on unit test (XCTestCase).Laullon
BTW PFFiles are not only for images.Laullon

1 Answers

0
votes

I guess you are calling [Parse setApplicationId:clientKey:] from your app target. Have you tried this from you unit test methods?

Class MainAppPFFile = [[NSBundle mainBundle]classNamed:@"PFFile"];
PFFile *f = [MainAppPFFile fileWithName:[NSString stringWithFormat:@"f_%d_%d.jpg",ctIdx,chIdx]