ios - Array index out of range error on conditional declaration Swift -


func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat {      if let getimurl = newslists[indexpath.section][indexpath.row].imageurl string?{          if getimurl != "none"{             return 230.0         };  return 70.0       }else{         return 70.0     } } 

the error appears when have bad connection, possibly causing newslists array populate slowly,

anyway, index out of bounds error refers line

if let getimurl = newslists[indexpath.section][indexpath.row].imageurl string?{

my question is, if there issue line shouldn't program run code in between else brackets?

is not purpose of conditional declaration?

if not, how prevent error?

the purpose of if let declaration unwrap string? optional. error when accessing array assume newslists[indexpath.section][indexpath.row] exists instead of checking it. try

if newslists.count > indexpath.section {    if newslists[indexpath.section].count > indexpath.row {       if let getimurl = newslists[indexpath.section][indexpath.row].imageurl as? string {           if getimurl != "none"{              return 230.0            }       }    } }  return 70.0 

also correct bad connection being problem. if data source , dependent on information relying on network request (which performed on background thread) there no guarantee data source populated when method called.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -