问题
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
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"];
Why does a subclassed PFObject can not point to a PFUser object?
Any help appreciated! Thanks a lot!
回答1:
I was able to get around this problem by first subclassing PFUser, then using my subclass called User
in my other PFObject subclasses.
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
and my 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
来源:https://stackoverflow.com/questions/26318276/pfuser-property-on-subclassed-pfobject