ios - Swift Parse: can not retrieve the value of a bool in _User class -


i developing app using swift , parse. reasons have implemented bool named "modified" in _user class. have been playing around swift , parse few months not make sense.

when try retrieve value of "modified" bool keep on getting "false" value though set on "true" on parse server. here code:

    var modified: bool = pfuser.currentuser().objectforkey("modified") as! bool     println("user modified bool set to: \(modified)") 

i have tried

    self.modified = pfuser.currentuser().valueforkey("modified") as! bool     println("user modified bool set to: \(modified)") 

and

    self.modified = pfuser.currentuser()["modified"] as! bool     println("user modified bool set to: \(modified)") 

do have make specific query or there way access value directly?

edit

i have implemented specific query. still "false" value though

        var querymainuser: pfquery = pfuser.query()     querymainuser.wherekey("username", equalto: pfuser.currentuser().username)     querymainuser.findobjectsinbackgroundwithblock { (mainusersobjects, mainuserserror) -> void in         if (mainuserserror == nil) {             var theref = mainusersobjects[0] as! pfobject             self.modified = theref["modified"] as! bool             println("any improvement? \(self.modified)")         }     } 

edit 2

following @danh advices, tried updating currentuser instance on device implementing code:

        var currentuser = pfuser.currentuser()     currentuser.fetchinbackgroundwithblock { (object, error) -> void in         println("refreshed")         currentuser.fetchifneededinbackgroundwithblock { (result, error) -> void in              self.modified = currentuser.objectforkey("modified") as! bool             var idofuser: string = currentuser.objectid             println("user \(idofuser) updated")             println(self.modified)             if self.modified == true {                 self.deletedata()                 self.fetchallobjects()             }         }     } 

when running console gives me this:

refreshed user xtbbw6cnzk updated false 

here screenshot took of server side: can't bool parse

thank attention

i not sure version of swift using. if using swift 2.0 , xcode 7, should job.

this not work:

let modifiedstatus = pfuser.currentuser()?["modified"] // return value nil 

this work sure:

let modifiedstatus = pfuser.currentuser()?.objectforkey("modified") print(modifiedstatus) // true per table 

i know may sound strange, struggle hours later realising silly mistake. move of current task , later recheck after few hours. make sure cross check following:

  • the key "modified" in main user class of parse
  • you can retrieve other key values (just see if nothing else wrong other current retrieving of key bool value(

though on swift 2.0, sure there no major change in specific code when comes move swift 1.2 swift 2.0.

just see , if still doesn't work, can discuss more on setup.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -