我已经使用以下类(动态属性,以及.m文件中的+ load& parseClassName方法)对PFObject进行了子类化
@interface DAOpponents : PFObject <PFSubclassing>
@property (nonatomic, strong) PFObject* fromUser;
@property (nonatomic, strong) PFObject* toUser;
@property (nonatomic) BOOL isVisible;
@property (nonatomic) BOOL isPersistent;
+ (NSString *)parseClassName;
@end
在单元测试中,我尝试创建一个示例DAOpponents-Object:
DAOpponents* follow = [DAOpponents object];
follow.fromUser = user1; // caught "NSInvalidArgumentException", "PFObject values may not have class: PFUser"
follow.toUser = user2;
[follow save];
如果我在没有对手的子类版本的情况下做同样的事情那就没有例外
PFObject* follow = [[PFObject alloc] initWithClassName:@"DAOpponents"];
[follow setObject:user1 forKey:@"fromUser"]; // no exception!!!
[follow setObject:user1 forKey:@"toUser"];
为什么子类PFObject不能指向PFUser对象?
任何帮助表示赞赏!非常感谢!
答案 0 :(得分:2)
我能够通过首先继承PFUser,然后在我的其他PFObject子类中使用名为User
的子类来解决这个问题。
我的PFUser子类,User.h:
#import <Parse/Parse.h>
@class Person;
@class Parish;
@interface User : PFUser<PFSubclassing>
//+ (NSString *)parseClassName;
// Return the current user
+ (User *)currentUser;
@property (retain) NSNumber *acceptedAgreements;
@property (retain) NSNumber *isAdmin;
@property (retain) Person *person;
@end
和我的User.m:
#import "User.h"
#import <Parse/PFObject+Subclass.h>
#import "Person.h"
@implementation User
@dynamic acceptedAgreements;
@dynamic isAdmin;
@dynamic person;
//+ (NSString *)parseClassName {
// return @"User";
//}
// Return the current user
+ (User *)currentUser {
return (User *)[PFUser currentUser];
}
@end