Storing photos and videos in Core Data?

后端 未结 2 494
悲&欢浪女
悲&欢浪女 2020-12-28 11:22

I am developing an app that lets the user record videos and photos. Now I am wondering what is the best way to store them?

The first idea is of course to save it in

2条回答
  •  忘掉有多难
    2020-12-28 11:53

    Use Code Data to store images and big files.

    Code Data can save binary data to disk for you automatically, just set this option on the properties of the attribute, you just need to activate the option to allow external storage and Core Data will do the magic for you, simple as that.

    Here you are the function to do in Swift3

    //Image
    let imageData = UIImageJPEGRepresentation(image, 1) // You can low compression up to >0
    
    //Video from URL
    let videoData = NSData(contentsOf:videoURL!)
    

    Its so simple! iOs sweet programming.

提交回复
热议问题