下面我有一个tableView委托方法
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
lessonView?.lessonName = (capturedLessons?[indexPath.row].name)!
lessonView?.instructorGradedTracked = capturedLessons![indexPath.row].instructorGraded!
lessonView?.expectedCompletionTimeTracked = capturedLessons![indexPath.row].expectedCompletionTime!
self.present(self.lessonView!, animated: true, completion: nil)
}
lessonName: String
instructorGraded: Bool
expectedCompletionTime: Int
我在设置bool和int值的nil值检查时遇到麻烦。实施此错误处理的最佳实践方法是什么?
最佳答案
你可以试试
guard let item = capturedLessons?[indexPath.row] ,let name = item.name, let graded = item.instructorGraded , let completionTime = item.expectedCompletionTime else { return }
lessonView?.lessonName = name
lessonView?.instructorGradedTracked = graded
lessonView?.expectedCompletionTimeTracked = completionTime
self.present(self.lessonView!, animated: true, completion: nil)
关于ios - 如何:在显示ViewController之前检查每个值是否为零,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59363989/