AVFoundation 类 未在 OSX xcode 项目中解决

AVFoundation classes not resolved in OSX xcode project

我启动了一个新的 Xcode 项目作为命令行/OSX/Swift 应用程序。我导入 AVFoundation 并在导入基础后将以下代码添加到顶级范围。

  let string = "Hello, World!"
  let utterance = AVSpeechUtterance(string: string)
  utterance.voice = AVSpeechSynthesisVoice(language: "en-US")

  let synthesizer = AVSpeechSynthesizer()
  synthesizer.speakUtterance(utterance)

编译器抱怨 AVSpeechUtterance 的标识符无法解析。我也在 Cocoa 应用程序中尝试过此操作,而不是命令行一。我也尝试过链接 AVFoundation,尽管我认为最近没有必要这样做。

为什么我的 xcode 项目无法编译?

我相信那些只存在于 iOS。在 OS X 上,可通过 NSSpeechSynthesizer.

获得类似的功能