简体   繁体   中英

How to store many images and .mp3 files in core data for iphone?

I am very new to core data and am trying to learn how to store large files, like images and short .mp3s. My app has about 300 different images and short .mp3s that are triggered to be displayed/played by user interaction, and as far as I can tell, I should use core data for storing these files.

I added a core data .xc file to my xcode project, and created an entity with attributes. I chose an attribute named "binary data" and checked the box "Allows External Storage," which from what I've read allows me to easily persistently sore files on 5.x or newer iOS phones. I know that I can program the app to get and set these attributes, but how do I just store my images and music files here?

Please help with me with code/understanding. It seems to me I should be able to somehow use the core data interface to set up a bunch of entities containing attributes of "binary data" that are my images and .mp3s, and whenever I need to display a pic or play a sound, I could call the entity and its attributes.

Thanks for the help!

I store compressed images (jpegs) with Core Data and it seems fast enough. But these are compressed to < 100K.

If you want to store items bigger than 100K, you might want to just save the file to "disk" doing something along the lines of Write a file on iOS

Then, save the file path to a string in Core Data. To load the file, get the file path from core data then read the file in.

I think Apple recommends the cutoff at 100K.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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