-2

I need help in this code,

I am trying to play sounds when a button is pressed on the iPhone app and I get this error. Here is the code

   -(IBAction)playSound:(id)sender{
  //  NSLog(@"play Sound");
    SystemSoundID soundID;
    NSString *buttonName = [sender currentTitle];
    NSString *soundFile = [[NSBundle mainBundle]
                           pathForResource:buttonName ofType:@"wav"];
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID);
    AudioServicesPlaySystemSound(soundID);
    [soundFile release];

The error messages say

Release is unavialable: not available in automatic reference counting mode

ARC forbids explicit message 'release'

*Cast of Objective-C pointer type 'id' to C pointer type 'CFURLRef' (aka 'const struct __CFURL ') requires a bridged cast

Community
  • 1
  • 1

2 Answers2

2

This error says that you have to use ARC so you do not need to release any object because it automatically counts its reference.

In your case, comment or remove every

[OBJ release];

Specifically, you need to remove [soundfile release];

BryanH
  • 5,826
  • 3
  • 34
  • 47
iPatel
  • 46,010
  • 16
  • 115
  • 137
  • I have made the changes and removed [Soundfile release]; but still coming up with this **Error** *Cast of Objective-C pointer type 'id' to C pointer type 'CFURLRef' (aka 'const struct __CFURL ') requires a bridged cast* What is wrong with this line of code? `AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID);` – Teddy Able Mar 18 '13 at 01:13
  • @TeddyAble- http://stackoverflow.com/questions/11703923/cfurlref-requires-a-bridged-cast-error this Question is helpful in your case...best of luck :) – iPatel Mar 18 '13 at 04:20
0

As you are using ARC (Automatic Reference Counting) in your project you do not need to release any objects as the compiler takes care if it for you.

Therefore you do not need [soundFile release];

Look at this apple document for more information on ARC

Jonathan King
  • 1,528
  • 14
  • 25