为什么不能将 recordAudioURL 分配给 segue.destination 对象?



我正在学习在线课程,教师代码有以下代码,但我收到错误。这可能是 Swift 或 Xcode 更新的问题。您将如何解决此错误?

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "stopRecording" {
let playsoundsVC = segue.destination as! PlaySoundsViewController
let recordedAudioURL = sender as! URL
playsoundsVC.recordedAudioURL = recordedAudioURL
}
}

代码的最后一行给出错误:

无法将类型"URL

"的值分配给类型"URL?"。类型'

edit1:PlaySoundsViewController文件的开头

class PlaySoundsViewController: UIViewController {
var recordedAudioURL = URL?.self
}

确保PlaySoundsViewController中的 var 是这样声明

class PlaySoundsViewController:UIViewController {
var recordedAudioURL:URL?
}

var recordedAudioURL:URL!如果它是 100% 它将被分配

最新更新