【问题标题】:PFObject values may not have class: PFFilePFObject 值可能没有类:PFFile
【发布时间】: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


【解决方案1】:

我猜你是从你的应用目标调用 [Parse setApplicationId:clientKey:] 。 你有没有从你的单元测试方法中尝试过这个?

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

【讨论】:

    猜你喜欢
    • 2014-07-25
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    • 1970-01-01
    相关资源
    最近更新 更多