swift - Can't I use nil for 'undefined' on parse? -


i making simple app, , implementing userinformation part. user can edit info, have trouble if user doesn't put info, crash when try retrieve data undefined column.

this code retrieve user data.now can check specific value, still, got error 'undefined' one.

 var query = pfquery(classname: "note")     query.getobjectinbackgroundwithid("kg8khawcms", block: {         (obj, error)in         if let obj = obj! as? pfobject {                 let nickname = (obj.objectforkey("text")) as! string                if (nickname != nil) {  ///// have error message binary operator'!=' cannot applied operands of type 'string' , 'niliteralconvertible'                     self.nicknamelabel.text = nickname              }else{                 self.nicknamelabel.text = "you don't have nick name"             }           } else {             print(error)         }     }) 

what 'niliteralconvertible' ? , i've tried well,

   var query = pfquery(classname: "note")     query.getobjectinbackgroundwithid("kg8khawcms", block: {         (obj, error)in         if let obj = obj! as? pfobject {                 let nickname = (obj.objectforkey("text")) as! string               if !(nickname.isempty) {                 self.nicknamelabel.text = nickname              }else{                 self.nicknamelabel.text = "you don't have nick name"             }           } else {             print(error)         }     }) 

so asking how can handle retrieving undefined value before crash? (please write full code me)

///like this

if (undefined in parse  == somekindoftype) {    print("yes")    } 

you can't use nickname != nil because have said cannot nil let nickname = (obj.objectforkey("text")) as! string.

the as! string unwraps obj.objectforkey("text") , @ cannot nil or error.

i suggest using following:

if let nickname = obj.objectforkey("text") as? string {     self.nicknamelabel.text = nickname } else{     self.nicknamelabel.text = "you don't have nick name" } 

perhaps beneficial read: swift literal convertibles


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -