ios - 如何: check for nil on every value before presentation of ViewController

标签 ios swift tableview

下面我有一个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/

相关文章:

ios - 如何在 xcode 8 中的 watch 和 iphone 之间共享数据

iphone - Apple ID 可以访问吗?

iphone - "Current location"文本应根据 iPhone 中的语言进行更改

ios - 在 UITabBarController 上的导航栏中添加按钮并从 View Controller 调用 Segue

ios - Swift 中的 UISlider iOS 应用程序自定义值

ios - 当键盘快速出现时 UICollectionViewCell 改变高度 4.2

swift - 在 iOS 中加载 TableView 数据时出现 TableView 部分问题

JavaFX TableView 分页 - 无法创建基于 fxml 的解决方案

ios - 从深度嵌套的 UIView 快速调用方法

java - FXML TableView "Class fxmlPerson does not support property "bestellnr"