How to solve Fatal error: Index out of range in Swift IOS

自闭症网瘾萝莉.ら 提交于 2019-12-04 22:06:24

Fatal error: Index out of range

This error only refers a thing that index, you want to access from the array does not exist.

let url = NSURL(string: feedImgs[indexPath.row] as! String)

In the above line feedImgs[indexPath.row] does not exist, that why you are getting the error. Make sure that your feedImgs array and myFeed array both are of same length because you are loading the table from myFeed array.

Or, You can can check like this.

if feedImgs.count > indexPath.row {
    let url = NSURL(string: (feedImgs[indexPath.row] ?? ""))
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!