我正在学习在线课程,教师代码有以下代码,但我收到错误。这可能是 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% 它将被分配