Person
是PFObject
的子类。
Address
也是PFObject
的子类。 Address
的{{1}}类型为@property
。
即
Person
两个子类都在// Person.h
@interface Person : PFObject<PFSubclassing>
@property (retain) NSString *firstName;
@property (retain) NSString *secondName;
+ (NSString *)parseClassName;
@end
// Person.m
#import <Parse/PFObject+Subclass.h>
@implementation PP4MEAddress
@dynamic firstName;
@dynamic firstName;
+ (NSString *)parseClassName {
return @"Person";
}
// Address.h
@interface Address : PFObject<PFSubclassing>
@property (retain) Person *deliverToPerson;
@property (retain) NSString *line1;
@property (retain) NSString *line2;
+ (NSString *)parseClassName;
// Address.m
#import <Parse/PFObject+Subclass.h>
@implementation PP4MEAddress
@dynamic deliverToPerson;
@dynamic line1;
@dynamic line2;
+ (NSString *)parseClassName {
return @"Address";
}
。
在App Delegate
中的方法中我想将它们设置为
e.g。
MyViewController
执行此代码时,类-(void)myMethod
{
Address *address = [Address object];
address.deliverToPerson.firstName = @"John";
address.deliverToPerson.secondName = @"Smith";
address.line1 = @"123";
address.line2 = @"Main Street";
[address saveInBackground];
}
的条目将输入到Parse.com Web App上的Address
。但是,唯一的列是Data Browser
,objectId
,createdAt
和updatedAt
我想这是因为,ACL
类型Address @property
不是Person
和allocated
。
我如何克服这个问题?
我是否为
撰写自定义initialised
和setter
getter
在@property (retain) Person *deliverToPerson;
?
如果有,我注意到Address.m
是@property
,因此我需要在atomic
和setter
中编写锁定代码吗?
谢谢
答案 0 :(得分:2)
我对parse.com并不熟悉,但我强烈认为你必须这样做
在设置关系之前分配Person
对象。像
Address *address = [Address object];
address.line1 = @"123";
address.line2 = @"Main Street";
Person *person = [Person object];
person.firstName = @"John";
person.secondName = @"Smith";
address.deliverToPerson = person;
[address saveInBackground];
答案 1 :(得分:0)
您必须设置PF对象 像这样
PFObject *anotherPlayer = [PFObject objectWithClassName:@"Player"];
[anotherPlayer setObject:@"DataValue" forKey:@"Name"];