Swift 4:强制从 'Data?' 强制转换为 'Data' 仅解包选项;您是想使用“!”吗?

Swift4: Forced cast from 'Data?' to 'Data' only unwraps optionals; did you meant to use '!'?

在上次更新 Swift 4 时,我总是在同一个地方遇到同样的错误,我不知道如何清除它...

如果尝试使用 !代替 ?但是错误一直朝着相反的方向发展。

两个日期都有错误?和数据?

这就是代码:

let done = UITableViewRowAction(style: .normal, title: doneTitle) { action, index in
        tableView.beginUpdates() // Beginne mit dem Update


        // error in the following line
        self.appDelegate.loanResource.editLoan(withObjID: (loan?.objectID)!, andName: (loan?.name)!, andAmount: (loan?.amount)!, andNote: (loan?.note)!, andCreated: loan?.created as! Date, andDue: (loan?.due) as! Date, andDone: nowDone, andImage: loan?.image as! Data, andContactInfoMail: (loan?.contactInfoMail)!, andContactInfoNumber: (loan?.contactInfoNumber)!, andChargeMode: (loan?.chargeMode)!, andChargeAmount: (loan?.chargeAmount)!, andReminder: (loan?.reminder)!, andReminderID: (loan?.reminderID)!)


        UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [(loan?.reminderID)!]) // Reminder entfernen, weil der Betrag zurück gezahlt wurde
        tableView.reloadData()
        self.loanList?.remove(at: indexPath.row) // Datensatz aus der Variable entfernen
        tableView.deleteRows(at: [indexPath], with: .fade) // Datensatz ausblenden
        tableView.endUpdates() // Update beenden
        vc?.setTotalAmount() // Gesamtwert aktualisieren
    }

所有其他错误都消失了,但这个错误让我头晕目眩。

假设贷款中的所有类型都符合预期的类型,以下应该有效:

if let loan = loan {
    self.appDelegate.loanResource.editLoan(withObjID: loan.objectID, andName: loan.name, andAmount: loan.amount, andNote: loan.note, andCreated: loan.created, andDue: loan.due, andDone: nowDone, andImage: loan.image, andContactInfoMail: loan.contactInfoMail, andContactInfoNumber: loan.contactInfoNumber, andChargeMode: loan.chargeMode, andChargeAmount: loan.chargeAmount, andReminder: loan.reminder, andReminderID: loan.reminderID)
    // more to to with the unwrapped loan
} else {
    // loan was nil
}