PFUser Property on subclassed PFObject

我怕爱的太早我们不能终老 提交于 2019-12-22 11:28:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!