Jaywant Khedkar Jaywant Khedkar - 9 months ago 79
Objective-C Question

How to add .mp3 files from NSBundle to NSArray in ios

I have list of .mp3 files in my Resources folder within an iOS 7.2 XCode project.I have add all .mp3 files in to one array,

Used Below code :

NSArray *array = [[NSBundle mainBundle] pathsForResourcesOfType:@".mp3" inDirectory:@"Resources"];

However I am not getting any record in NSArray,What is wrong I did in above code, How to add my .mp3 files in to array if any one know please tell me.

Answer Source

The "Resources" folder won't actually exist in the app bundle. That's just a group in your Xcode project. And don't add the "." to the type.

Your line of code should be:

NSArray *array = [[NSBundle mainBundle] pathsForResourcesOfType:@"mp3" inDirectory:nil];