无法在PFUser

时间:2015-12-10 11:49:02

标签: ios swift parse-platform pfuser pfrelation

我知道这个问题已被问到很多,但没有一个解决方案符合我的情况。我正在尝试将对象添加到当前用户的关系中。请注意,除非具有PFRelation的对象是PFUser,否则向关系添加对象没有问题。

以下工作正常:

let testChild: PFObject = PFObject(className: "TestChild")
testChild["name"] = "test"
testChild.saveInBackgroundWithBlock { (success, error) -> Void in
  let testParentQuery: PFQuery = PFQuery(className: "TestParent")
  testParentQuery.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
    let testParent: PFObject = (objects?.first)!
    let testRelation: PFRelation = testParent.relationForKey("children")
    testRelation.addObject(testChild);
    testParent.saveInBackground()
   })
}

但这不起作用:

let testChild2: PFObject = PFObject(className: "TestChild")
testChild2["name"] = "test"
testChild2.saveInBackgroundWithBlock { (success, error) -> Void in
  let testRelation: PFRelation = (PFUser.currentUser()?.relationForKey("testRelation"))!
  testRelation.addObject(testChild2)
  PFUser.currentUser()?.saveInBackground()
}

我检查/双重检查PFUser.currentUser()返回一个有效值,testRelation存在,具有正确的名称,类型等。此外,TestChild对象保存得很好,它记录了错误<{1}} < / p>

  

&#34; 无法添加指向关系的非指针(代码:111,版本:1.10.0)&#34;好像我试图为这种关系设置字符串或其他东西,尽管我显然不是。此外,我没有问题设置/保存用户的非关系字段(如字符串)。我正在将PFUser和我想要添加到关系中的对象子类化,但是试图缩小问题范围,我尝试了上面的代码并在代码中仅使用PFUser和PFObject。

我做错了什么?请帮忙,我已经被困了几个小时了,我只是无法理解发生了什么。

0 个答案:

没有答案