gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:20:19 26 4
gpt4 key购买 nike

[X-Post from parse.com]

PersonPFObject子类 .

Address也是 PFObject子类 . Address有一个 @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中注册了.

MyViewController 中的一个方法中我想这样设置这些

例如

-(void)myMethod
{

Address *address = [Address object];
address.deliverToPerson.firstName = @"John";
address.deliverToPerson.secondName = @"Smith";
address.line1 = @"123";
address.line2 = @"Main Street";
[address saveInBackground];

}

执行此代码时,Class Address 的条目被输入到 Data Browser在 Parse.com Web 应用程序上。但是,唯一的列是 objectId , createdAt , updatedAtACL

我想这是因为,在引擎盖下 Address @property类型 Person不是 allocatedinitialised .

我该如何克服这个问题?

我要写一个自定义 settergetter对于

@property (retain) Person *deliverToPerson;

Address.m

如果是这样,我注意到 @propertyatomic因此我需要在 setter 中编写锁定代码和 getter

谢谢

最佳答案

我不熟悉 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];

关于ios - PFObject 子类作为另一个 PFObject 子类中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20584613/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com