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

时间:2018-09-17 18:39:33

标签: ios swift xcode

我正在学习在线课程,并且讲师代码包含以下代码,但出现错误。 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?.Type”

edit1:PlaySoundsViewController文件的开始

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

1 个答案:

答案 0 :(得分:0)

确保PlaySoundsViewController中的var声明如下

class PlaySoundsViewController:UIViewController {
   var recordedAudioURL:URL?
}

var recordedAudioURL:URL!(如果为100%,则将被分配