PFObject子类作为另一个PFObject子类中的属性

时间:2013-12-14 14:41:43

标签: ios iphone objective-c subclass parse-platform

[X-Post from parse.com]

PersonPFObject子类

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 BrowserobjectIdcreatedAtupdatedAt

我想这是因为,ACL类型Address @property不是Personallocated

我如何克服这个问题?

我是否为

撰写自定义initialisedsetter
getter

@property (retain) Person *deliverToPerson;

如果有,我注意到Address.m@property,因此我需要在atomicsetter中编写锁定代码吗?

谢谢

2 个答案:

答案 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"];