gpt4 book ai didi

swift - 为什么不能将 NSSpeechsynthesier 的类方法 availableVoices 桥接到 Swift 字符串数组?

转载 作者:行者123 更新时间:2023-11-28 14:45:46 25 4
gpt4 key购买 nike

在苹果的 Working with Cocoa Frameworks它看起来好像 Foundation 和 Swift Foundation 框架通过桥接一起工作。但是,我注意到在尝试使用 NSSpeechSynthesizer 的类方法 availableVoices() 时,它允许我接收到返回的 NSString 数组,但不是字符串。

编译和运行都很好:

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

但是这不会编译:

let voicesTwo = NSSpeechSynthesizer.availableVoices as [String]

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

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

最佳答案

看起来 NSSpeechSynthesizer.VoiceName 是一个 Enum,其 rawValueString。这与成为字符串不同。

尝试使用

NSSpeechSynthesizer.availableVoices.map { $0.rawValue }

关于swift - 为什么不能将 NSSpeechsynthesier 的类方法 availableVoices 桥接到 Swift 字符串数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50272695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com