swift - Get data from tableView row data (unexpectedly found nil) -


i populating tableview array can't seem set textlabel property using row's object. here's relevant code:

let object = realmatches[indexpath.row]  username = object["first_name"] as! string  cell.textlabel?.text = username  return cell 

i following error when try set username variable (which later used set cell.textlabel property): unexpectedly found nil while unwrapping optional value

my realmatches array returning results know array not nil. think issue don't have "first name" property in matches table. it's located in user table, have pointer value in matches table points corresponding user. i'm using parse backend.

i tried using lengthy pfquery object's first_name doesn't seem pull results:

 var objectuser1 = object["user1"] as! pfuser             var objectuser2 = object["user2"] as! pfuser              var userquery = pfquery(classname: "user")             userquery.wherekey("objectid", equalto: objectuser1.objectid!)              var userquery2 = pfquery(classname: "user")             userquery2.wherekey("objectid", equalto: objectuser2.objectid!)              var query = pfquery.orquerywithsubqueries([userquery, userquery2])             query.includekey("user1")             query.includekey("user2")             query.findobjectsinbackgroundwithblock{                 (results: [anyobject]?, error: nserror?) -> void in                  if error != nil {                     println(error)                 } else {                      if results != nil {                          result in results!{                              username = result["first_name"] as! string                         }                     }                 }             } 

any ideas on how can set cell's textlabel property match's first name?

thanks!

edit: adding data structure of realmatches. here output when println(realmatches):

<match: 0x7fa03b5a6610, objectid: fq2oaoeggc, localid: (null)> {     user1 = "<pfuser: 0x7fa03b75e7b0, objectid: aelmsjgrxm>";     user2 = "<pfuser: 0x7fa03b7b9310, objectid: ljtri8el8w>"; }, <match: 0x7fa03b561d80, objectid: kdj6hg1v4f, localid: (null)> {     user1 = "<pfuser: 0x7fa03b7b9ca0, objectid: aelmsjgrxm>";     user2 = "<pfuser: 0x7fa03b47d670, objectid: w1ukrertdm>"; }] 

here's actual backend data structure:

match table:
-objectid
-user1 (pointer)
-user2 (pointer)

user table:
-objectid
-first_name


Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -