我试图解析PFRelation的问题.我有一个名为“girlBio”的课程,它存储有关女孩的信息,还有一个名为“stuff”的课程,用于存储有关项目的信息.代码如下:
PFObject *item = [PFObject objectWithClassName:@"stuff"]; item[@"Name"] = @"PS3"; PFObject *girl = [PFObject objectWithClassName:@"girlBio"]; girl[@"Name"] = @"Jessica"; PFObject *girl2 = [PFObject objectWithClassName:@"girlBio"]; girl2[@"Name"] = @"Cindy"; PFRelation *relation = [item relationForKey:@"owners"]; [relation addObject:girl]; [relation addObject:girl2]; [item saveInBackground];
———————————更新也试过这个————- ————
PFObject *item = [PFObject objectWithClassName:@"stuff"]; item[@"Name"] = @"PS3"; PFObject *girl = [PFObject objectWithClassName:@"girlBio"]; girl[@"Name"] = @"Jessica"; [item saveInBackground]; [girl saveInBackground]; PFRelation *relation = [item relationForKey:@"owners"]; [relation addObject:girl]; [item saveInBackground];
所以我希望这个项目由几个女孩拥有,但是当我运行该程序时,我收到此错误:
错误:无法向关系添加非指针(代码:111,版本:1.6.0)
有人可以帮忙吗?
谢谢
@H_502_16@解决方法
在保存关系之前,您需要保存对象girl1和girl2.否则,即使您的本地副本知道它们,服务器也不会.
UPDATE
在保存关系之前,还需要确保girl1和girl2的保存以及项目完成.但是,您可能不希望在主线程上运行这些保存,因此我建议这样的(我刚刚运行时没有问题):
dispatch_async(dispatch_get_main_queue(),^{ PFObject *item = [PFObject objectWithClassName:@"stuff"]; item[@"Name"] = @"PS3"; PFObject *girl = [PFObject objectWithClassName:@"girlBio"]; girl[@"Name"] = @"Jessica"; [item save]; [girl save]; PFRelation *relation = [item relationForKey:@"owners"]; [relation addObject:girl]; [item saveInBackgroundWithBlock:^(BOOL succeeded,NSError *error) { //Do something after the last save... }]; });@H_502_16@ @H_502_16@ 原文链接:https://www.f2er.com/iOS/327820.html