【发布时间】:2015-03-26 00:08:46
【问题描述】:
当我尝试将图像保存在 Parse 对象上时,出现此错误“PFObject values may not have class: PFFile”...
这是代码和对象:
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
有什么想法吗?
【问题讨论】:
-
感谢 Fabio,但不是同一个问题,我已经在使用 PFFile。
-
是的,但你不能像现在这样分配它......你需要在执行 PFFile 之前像 UIimage 一样传递它。
-
不,这不是问题,因为相同的代码适用于应用程序,我忘了提到问题是当代码在单元测试 (XCTestCase) 上运行时。
-
BTW PFFiles 不仅适用于图像。
标签: ios objective-c parse-platform