【问题标题】:Why can't NSSpeechsynthesier's class method availableVoices be bridged to a Swift array of strings?为什么 NSSpeechsynthesier 的类方法 availableVoices 不能桥接到 Swift 字符串数组?
【发布时间】:2018-05-10 12:11:09
【问题描述】:

在 Apple 的 Working with Cocoa Frameworks 中,它读起来好像 Foundation 和 Swift Foundation 框架通过桥接一起工作。但是,我注意到在尝试使用 NSSpeechSynthesizer 的类方法 availableVoices() 时,它允许我接收返回的 NSStrings 数组,但不能接收 Strings。

这编译并运行得很好:

let voices = NSSpeechSynthesizer.availableVoices as [NSString]
        print(voices)

但是这不会编译:

let voicesTwo = NSSpeechSynthesizer.availableVoices as [String]

如果the voiceName documentation 显示 VoiceName 是一个字符串属性,为什么这不起作用?

我在 VoiceName 文档中看到了“rawValue”一词,那么推理是否与某种枚举有关?

【问题讨论】:

    标签: swift cocoa toll-free-bridging


    【解决方案1】:

    看起来NSSpeechSynthesizer.VoiceNameEnumrawValueString。这与 作为 字符串不同。

    尝试使用

    NSSpeechSynthesizer.availableVoices.map { $0.rawValue }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-28
      • 1970-01-01
      • 2023-01-05
      • 1970-01-01
      • 2011-11-08
      • 2010-12-16
      相关资源
      最近更新 更多