Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App (iOS7) Animating and Intercepting Events Adding Sound

Jacob McLaws
Jacob McLaws
1,497 Points

NSString *soundPath not responding correctly.

Not sure what's wrong here. I get build failed even though my code matches Amit's in the video. I think I imported and added the correct framework. I'm puzzled. Also don't know why my code isn't turning purple in the same places (pathForResources ofType etc, ect.)

Thanks for the support! Below is a link to the xcode file.

https://www.dropbox.com/sh/qqd61pfhaiujlw6/AABQK-xZRVy2CAUkqN417DrMa?dl=0

1 Answer

Kieran Robinson
Kieran Robinson
9,411 Points

Hello Jacob McLaws! I just had a look over the code, and I fixed the error. The problem was in the following two lines

NSString *soundPath = [[[NSBundle mainBundle] pathForResource:@"crystal_ball" ofType:@"mp3"];
NSURL *soundURL = [[NSURL fileURLWithPath:soundPath]];

There was an extra square bracket ('[') at the beginning of the 'NSBundle mainBundle] line. and also an extra set of the same square brackets is around the second line around the 'NSURL line'.

NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"crystal_ball" ofType:@"mp3"];
NSURL *soundURL = [NSURL fileURLWithPath:soundPath];

This should fix the problem and i understand how frustrating it can be!!

Hope it helps, Kieran

Jacob McLaws
Jacob McLaws
1,497 Points

Thanks Keiran. It IS very frustrating. Always great to have good pals to help out!