我已经将PFUser子类化了,添加了几个直接转换为数据库存储的属性,例如gender和birthDate:
// Define property
@property(retain, nonatomic) NSDate *birthDate;
// and later on...
// Instruct compiler to leave setter/getter up to us (Parse)
@dynamic signUpComplete, birthDate, paypalEmail, gender;
这些属性工作正常,并致力于可靠存储。
我的问题:如何添加常规私人' 不的属性是否存储在数据库中??
我最初的想法是像往常一样简单地定义常规属性,并在它们上调用@syntheize而不是@dynamic。这个似乎可以正常工作,但是Parse确实向控制台转发了一条关于PFUser Key Not Found的消息。
@synthensize是否会阻止仅本地属性可靠地写入db?
答案 0 :(得分:0)
我会覆盖PFUser子类中的saveInBackground:
方法,以实现您的目标。像这样:
标题文件:
@interface PFUserSubclass : PFUser
@property (nonatomic, strong) NSString *customPropertyToSave;
@property (nonatomic, strong) NSString *customPropertyToIgnore;
- (void)saveInBackgroundWithBlock:(PFBooleanResultBlock)block;
@end
实施档案:
@implementation PFUserSubclass
@synthesize customPropertyToSave;
@synthesize customPropertyToIgnore;
- (void)saveInBackgroundWithBlock:(PFBooleanResultBlock)block {
PFUser *userToSave = [PFUser currentUser];
[userToSave setObject:self.customPropertyToSave forKey:@"customProperty"];
[userToSave saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
block(succeeded, error);
}];
}
@end