swift - 为什么 NSSpeechsynthesier 的类方法 availableVoices 不能桥接到 Swift 字符串数组?
问题描述
在 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]
如果voiceName 文档显示 VoiceName 是一个字符串属性,为什么这不起作用?
我在 VoiceName 文档中看到了“rawValue”一词,那么推理是否与某种枚举有关?
解决方案
它看起来像是NSSpeechSynthesizer.VoiceName
一个Enum
与一个rawValue
的String
。这与作为字符串不同。
尝试使用
NSSpeechSynthesizer.availableVoices.map { $0.rawValue }
推荐阅读
- editor - 制作编辑器用什么?
- python - eval函数Python的错误输出
- r - 如何正确格式化读取用户输入的 CodeChef 提交
- azure - CORS 策略问题:请求的资源上不存在“Access-Control-Allow-Origin”标头。网络核心 3.1
- python - 在给定的时间戳获取所有持有 ERC20 代币的地址
- python-3.x - 如何正确检测 dask/pandas 中的数据类型?
- r - 带有 R Markdown 和 Latex 的内联代码引发意外符号错误
- django - 在 Django 中创建一对一查询集
- excel - 在 Excel 中测量 DAX
- flutter - ImageIcon 被压扁的颤动