ios - How to convert PFObject to PFRelation -


here code in swift

@ibaction func adduser(sender: anyobject) {     var query = pfuser.query()     query.wherekey("username", equalto: usernametextfield)     query.getfirstobjectinbackgroundwithblock{ (objects:pfobject!, error: nserror!) -> void in          if error == nil {             var friendlist = pfuser.currentuser().relationforkey("friends") //  don't understand relationforkey, do? , happen inside ( )?              var addfriend = objects             if addfriend != nil {                 pfrelation.addobject(addfriend!) // <- error here                 println("added")             }             pfuser.currentuser().saveinbackgroundwithblock{                 (succeeded: bool!, error: nserror!) in                  if error != nil {                     println("error")                 }                 else {                     println("saved")                 }             }         }      } } 

i want let app able add other users via username parse , have trouble pfrelation.addobject(addfriend!). shows cannot add pfobject method since inside ( ) has pfrelation object don't know how convert this.
helps appreciated. thank you!

first of all, make sure have correct naming convention. usernametextfield instance of uitextfield or string? careful it.

for question, pfrelation not know objects associate. how can relate using addobject then? also, can not directly call addobject using pfrelation because addobject not factory method.

here need do, type here , might have errors:

let currentuser = pfuser().currentuser() let relation = currentuser.relationforkey("friend") // assume name of relation column friend relation.addobject(objects) // please careful naming convention. should use object name here  // save using saveinbackgroundwithblock 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -