问题描述
我用以下类(动态属性以及.m文件中的+ load& parseClassName方法)对PFObject进行了子类化
I've subclassed the PFObject with the following Class (dynamic properties, and +load & parseClassName Methods in .m file)
@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:
In a Unit Test I try to create a Sample DAOpponents-Object:
DAOpponents* follow = [DAOpponents object];
follow.fromUser = user1; // caught "NSInvalidArgumentException", "PFObject values may not have class: PFUser"
follow.toUser = user2;
[follow save];
如果我在没有对手的子版本的情况下做同样的事情,那就没有例外
If I do the same without a subclassed Version of the opponents there's no Exception
PFObject* follow = [[PFObject alloc] initWithClassName:@"DAOpponents"];
[follow setObject:user1 forKey:@"fromUser"]; // no exception!!!
[follow setObject:user1 forKey:@"toUser"];
为什么子类PFObject不能指向PFUser对象?
Why does a subclassed PFObject can not point to a PFUser object?
任何帮助表示赞赏!非常感谢!
Any help appreciated! Thanks a lot!
推荐答案
我能够通过首先将PFUser子类化,然后在其他PFObject子类中使用名为User
的子类来解决此问题.
I was able to get around this problem by first subclassing PFUser, then using my subclass called User
in my other PFObject subclasses.
我的PFUser子类User.h:
My PFUser subclass, 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
这篇关于子类PFObject上的PFUser属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!