Saving videos to Core Data?

How i can save video from photo library in Core Data?


When i want to save images, i use UIImagePNGRepresentation and save in Core Data like a data binary, but videos?

Replies

I would save them elsewhere and only add a link string into your db.

Post not yet marked as solved Up vote reply of KMT Down vote reply of KMT

Any help?

How big do you expect these videos to be? If they’re even remotely large (at most 64 KiB) you really do want to store them in an external file and reference them from Core Data as suggested by KMT.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

The videos would be recorded with the iPhone camera so they will be larger than 64KiB.

What can i do?

Store in a cloud or device?

And how?

Thanks.

Store in a cloud or device?

It seems like you should base that decision on the user experience you want, which isn’t something I can advise you on.

What can i do?

There’s two basic strategies here:

  • Core Data has the notion of attributes that use external storage. This is a good way to store large, relatively immutable chunks of data in your Core Data store.

  • Alternatively, you could manage the videos as an entirely separate file and just save a reference to that file; this could be as simple as putting all the files in a known directory and storing the file name in the Core Data store.

For large videos I’d probably go with the second choice because you’re never going to want to load this context into memory en masse.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"