guri23
guri23

Reputation: 65

How to store .mp3 file into Core Data?

I found this code to save the file on disk:

char *saves = "abcd";
NSData *data = [[NSData alloc] initWithBytes:saves length:4]; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"MyFile"];
[data writeToFile:appFile atomically:YES];

I am new to Core Data. I want to store MP3 files using it. First I want to download it from web URL, then save it in core data.

Upvotes: 1

Views: 693

Answers (1)

Alex
Alex

Reputation: 8991

You should save the files in the application documents directory (perhaps create a "music" subfolder), and store a reference to those files in Core Data. Ensure that these file are named uniquely (NSUUID may be useful) and that you don't store the path to the file on your managed object, since this is not guaranteed to be the same next time the application runs.

Upvotes: 2

Related Questions