小编Luk*_*ers的帖子

如果没有互联网连接,IOS 应用程序会在一行代码上崩溃,我该如何防止这种情况发生

这个代码和它在“尝试!”时崩溃,但我不知道如何捕捉错误并且它是明确的,否则它将无法工作。

func downloadPicture2(finished: () -> Void) {          
    let imageUrlString = self.payments[indexPath.row].picture
    let imageUrl = URL(string: imageUrlString!)!
    let imageData = try! Data(contentsOf: imageUrl)
    cell.profilePicture.image = UIImage(data: imageData)
    cell.profilePicture.layer.cornerRadius = cell.profilePicture.frame.size.width / 2
    cell.profilePicture.clipsToBounds = true        
}
Run Code Online (Sandbox Code Playgroud)

crash xcode ios swift

-1
推荐指数
1
解决办法
61
查看次数

标签 统计

crash ×1

ios ×1

swift ×1

xcode ×1