Code refactor by using URLForResource method instead of using the PathForResource method both in Obj-C and Swift

Obj-C

NSString *path = [[NSBundle mainBundle] pathForResource:@"play" ofType:@"mp3"];NSURL *playURL = [NSURL fileURLWithPath:path];

Swift

let path = Bundle.main.path(forResource: "play", ofType: "mp3")!let playURL = URL(fileURLWithPath: path)

Obj-C

NSURL *playURL = [[NSBundle mainBundle] URLForResource:@"play" withExtension:@"mp3" subdirectory:@"Music"];

Swift

let playURL = Bundle.main.url(forResource: "play", withExtension: "mp3", subdirectory: "Music")!

--

--

Software Engineer (Android, iOS, Unity) | M.Sc. Computer Science — Technische Universitaet Berlin | Mobile Advertising, Attribution, Monetisation, UA & Analytic

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akarsh SEGGEMU

Akarsh SEGGEMU

Software Engineer (Android, iOS, Unity) | M.Sc. Computer Science — Technische Universitaet Berlin | Mobile Advertising, Attribution, Monetisation, UA & Analytic