下面我有一个tableView委托(delegate)方法
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 - 如何: check for nil on every value before presentation of ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59363989/