ios - Cant't take an object id from a parse object and use it in other sections of code -
ive spent countless hours trying figure out why can't seem take object id of object has been saved parse , use in other sections of code. yes have searched , found topics on stack overflow , other websites , have read parse.com documentation none of answers allow me fix issue. pretty new coding , familiar swift @ moment. if can me figure out more appreciate help.
i declare objectid string variable @ top of code. later when send button tapped save data parse , attempt capture datas objectid passing objectid variable savetoparse function inout. project not show errors. code builds , runs. nslog(id) shows me proper objectid want in console. not show when nslog(self.objectid) called outside of function.
like said, i'm trying use objectid outside function in other parts of code, doesn't want save objectid variable. i've tried many other methods , closest have got making work.
im new @ hope i've explained situation clearly, if need more information solve don't hesitate ask. reading :)
var objectid:string = string() // declared @ top (underneath class) @ibaction func sendquestiontapped(sender: uibutton) { // send question , answers parse savetoparse(&objectid) // save question object id nslog(self.objectid) // test if objectid still question.objectid // move results view controller information performseguewithidentifier("toresultssegue", sender: self) } func savetoparse(inout id:string) { var question = pfobject(classname:"question") question["question"] = questiontopass question["answers"] = arraytopass question.saveinbackgroundwithblock { (success: bool, error: nserror?) -> void in if (success) { // object has been saved. dispatch_async(dispatch_get_main_queue()) { id = question.objectid! nslog(id) } } else { // there problem, check error.description if error != nil { nslog(error!.localizeddescription) } } } }
Comments
Post a Comment