parse.com - Swift Index out of Range at cellForRowAtIndexPath with two calls for getDataInBackground -


i having problem app crashing , giving index out of range error, after eliminated function imagefiles in background, imagefiles[indexpath.row].getdatainbackground tableview runs normally. think problem 2 getdatainbackgroundcalls confusing it.

however, still need download data imagefiles, i'm wondering if has solution how can within cellforrowatindexpath. appreciated:)

   override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecell(withidentifier: "userphotofeedcell", for: indexpath) as! feedcell      if pfuser.current()?.objectid != nil {          cell.userusername.text = pfuser.current()?.username      }       //downloades images , items populate user post     postimagefiles[indexpath.row].getdatainbackground { (data, error) in          if let userpostimagedata = data {              let downloadeduserpostimage = uiimage(data: userpostimagedata)              cell.userfeedphoto.image = downloadeduserpostimage          }       }      /* if isn't commented app gives index out of range crash     //downloads images user profile pic       imagefiles[indexpath.row].getdatainbackground { (data, error) in       if let imagedata = data {       let downloadedimage = uiimage(data: imagedata)       cell.userprofilepic.image = downloadedimage       }        }     */      cell.postlocation.text = postlocation[indexpath.row]      cell.postcaption.text = postcaptions[indexpath.row]      cell.userfeedphoto.image = uiimage(named: "orangefuego")      cell.userprofilepic.image = uiimage(named: "usericon.png")      return cell  } 

if feasible load image using url, can make use of sdwebimage library, downloads images in background, has options set place holder image until original image fetched. provides options caching images. here link library: https://github.com/rs/sdwebimage


Comments