swift - 在 Swift 中使用 AVAsynchronousKeyValueLoading

标签 swift avfoundation

我很好奇是否有一种快速、安全的方法来使用 AVAsynchronousKeyValueLoading 而无需对我正在使用的键进行硬编码。具体来说,我想使用键 "availableMdiaCharacteristicsWithMediaSelectionOptions" 调用 loadValuesAsynchronously(forKeys:completionHandler:),但目前无法获取 String 来自任何类型的基于 KeyPath 的解决方案。如果有某种方法可以检索属性的名称,以便在编译时检查该属性是否存在,我会很高兴。有这样的API吗?

最佳答案

解决方案是#keyPath。出于某种原因,我认为 KeyPath 已经替换了 Swift 中的 #keyPath,但是 #keyPath(AVAsset.availableMediaCharacteristicsWithMediaSelectionOptions) 给出了字符串 ” availableMediaCharacteristicsWithMediaSelectionOptions" 这正是我想要的。

关于swift - 在 Swift 中使用 AVAsynchronousKeyValueLoading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51070242/

相关文章:

ios - 如何在 Swift 中正确计算年龄?

ios - 在AVComposition中处理后丢失音频

iphone - 使用 AVMutableAudioMix 调整 Assets 内轨道的音量

ios - 如何为高分辨率静止图像和低分辨率(视频)预览配置 AVCaptureSession?

ios - UI 测试期间无法触发照片删除窗口

ios - "This application is modifying the autolayout engine"错误(Swift iOS)

ios - 将 "activity indicator"添加到TableView并在Swift中恢复为 "disclosure indicator"

ios - 使用 AVFoundation 框架进行条码扫描的错误结果

ios - 确定核心音频 AudioBuffer 中的帧数

ios - Swift 中的表单验证