简体   繁体   English

迅捷:如何从资产目录中获取资产

[英]swift: How do I get an asset from the asset catalog

Using WatchKit, when trying 尝试时使用WatchKit

  let asset = NSDataAsset(name:"ASSET-NAME")

XCode throws the following error Use of unresolved identifier 'NSDataAsset' XCode引发以下错误Use of unresolved identifier 'NSDataAsset'

So how do I get a (sound) file from the asset catalog using WatchKit? 那么,如何使用WatchKit从资产目录中获取(声音)文件?

According to another thread you can get your audio file with 根据另一个线程,您可以使用

let filePath = Bundle.main.path(forResource: "fileName", ofType: "m4a")!
let fileUrl = URL(fileURLWithPath: filePath)
let asset = WKAudioFileAsset(URL: fileUrl)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM