adventurejoe
adventurejoe

Reputation: 13

expected identifer or "(" Objective C

I am incredibly new to xcode and im making an app for a school project. I am working on a background music code to play/pause on the same button (found the code but modified it some). I've been able to clear up the other errors but I don't know what to do about this... expected identifier or "("

@implementation settingscontroller2

-(void) btnAction:(UIButton*)button{
button.selected = !button.selected;}

{ //expected Identifier or "("


if (button.selected){

    // Play
    NSString *path = [[NSBundle mainBundle] pathForResource:@"app" ofType:@"mp3"];
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
    theAudio.numberOfLoops = -1;
    [theAudio play];
}

else (!button.selected){

    // Pause
    [theAudio pause];
    return.nil
}
}

Upvotes: 0

Views: 120

Answers (5)

Balu
Balu

Reputation: 8460

once check this one,

-(void) btnAction:(UIButton*)button{
    button.selected = !button.selected;


    if (button.selected){

        // Play
        NSString *path = [[NSBundle mainBundle] pathForResource:@"app" ofType:@"mp3"];
        theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
        theAudio.delegate = self;
        theAudio.numberOfLoops = -1;
        [theAudio play];
    }

    else if(!button.selected){//here also one problem in your code.

        // Pause
        [theAudio pause];
        //return.nil
    }
}

Upvotes: 1

Caleb
Caleb

Reputation: 125037

-(void) btnAction:(UIButton*)button{
    button.selected = !button.selected;}

{ //expected Identifier or "("

You've got two method bodies here. It looks like you should probably remove the first } and the next {, and maybe reformat a bit, so that you have:

-(void) btnAction:(UIButton*)button
{
    button.selected = !button.selected;
    if (button.selected){

Upvotes: 1

gipi
gipi

Reputation: 2515

try to remove the } at the end of

button.selected = !button.selected;

and the line that gives you error.

Upvotes: 0

yinkou
yinkou

Reputation: 5766

In your line

button.selected = !button.selected;}

The "}" is too much as the following "{".

Upvotes: 1

alxppp
alxppp

Reputation: 107

Try to replace the second last line with return;

Upvotes: 0

Related Questions