How do I store mp4 file as Data or NSData object in iOS?

153 Views Asked by At

How would I store media of type mp4 as an object of Data or NSData in iOS? I need to do this as a step toward saving the mp4 file as a CKAsset in CloudKit.

I would like to do what this post on stackoverflow does with an image object, except I want to do it with an mp4 file.

1

There are 1 best solutions below

0
Ian L On BEST ANSWER

I've not tried this, but maybe the Data initializer that takes a URL would do the trick:

init(contentsOf:options:)

E.g.:

let url = Bundle.main.url(forResource:"myFile", withExtension:"mp4")
let data = Data(contentsOf: url)

See the Apple docs