Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift: How do I get an asset from the asset catalog

Using WatchKit, when trying

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

XCode throws the following error Use of unresolved identifier 'NSDataAsset'

So how do I get a (sound) file from the asset catalog using WatchKit?

like image 310
Harcker Avatar asked Oct 22 '25 12:10

Harcker


1 Answers

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)
like image 119
sundance Avatar answered Oct 25 '25 03:10

sundance



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!