Reputation: 13
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
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
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
Reputation: 2515
try to remove the }
at the end of
button.selected = !button.selected;
and the line that gives you error.
Upvotes: 0
Reputation: 5766
In your line
button.selected = !button.selected;}
The "}" is too much as the following "{".
Upvotes: 1