Strange build fail


#1

Hi
Expected ‘;’ after method prototype :astonished:

Indicated i need ; just after this line

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

If i add ; i get a whole lot of new errors, i have added my code , i cant think what i may have typed wrong, :confused:

//
// QuizViewController.m
// Quiz
//
// Created by Imran Raja on 21/05/2012.
// Copyright © 2012 MyCompanyName. All rights reserved.
//

#import “QuizViewController.h”

@interface QuizViewController ()

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

//call the init method initialized by the superclass

self = [super initWithNibname:nibNameOrNil bundle:nibBundleOrNil];

if (self) {

//make to arrays and make pointers to the

questions = [NSMutableArray alloc[init];
answers = [NSMutableArray alloc[init];

//add questions and answers to the array

[question addObject:@“what is 7 + 7”];
[answer addObject:@“14”];

[question addObject:@“what is the capitold of verhmont”];
[answer addObject:@“monpelier”];

[question addObject:@“from what is tea made?”];
[answer addObject:@“milk tea leaves sugar and water”];
}
//return the addresss of the new object

return self;

         }

-(IBAction)showQuestion:(id)sender
{
// step to the next question

currentQuestionIndex++;
                          
// am i past the last one
if (currentQuestionIndex == [questions count]) {

// go back to first question
                              

currentQuestionIndex = 0;

}

// get the string at the index question array


NSString *question =[questions objectAtIndex:currentQuestionIndex];

//log the string to the console
NSLog:(@"display question : %@", question);

//diplay text in question feild

[questionField setText];

// clear the answer field
[answerField setText:@"???"];
                          
-(IBAction)showAnswer:(id)sender
                          {
//what is the answer to the current object
NSString *answer = [answers objectAtIndex:currentQuestionIndex];

//display it to the answer field
[answerField setText:answer];
                              
                          }
                          
                      }

@end


#2

In the QuizViewController.m implementation file there should be a line that says @implementation QuizViewController. It looks like you might have placed your implementation inside the class extension boilerplate code that Apple added with the newer version of Xcode. Try deleting the @interface QuizViewController () line and replace it with @implementation QuizViewController.


#3

hi thanks it now gives me this error

!expected expression at this line -(IBAction)showAnswer:(id)sender

following on code

-(IBAction)showAnswer:(id)sender
                          {
//what is the answer to the current object
NSString *answer = [answers objectAtIndex:currentQuestionsIndex];

//display it to the answer field
[answerField setText:answer];
                              
                          }

}


#4

Might be an issue of mismatched curly braces. Try deleting the extra curly brace “}” before the @end. Make sure that all your methods have matching opening and closing curly braces.


#5

nope no help there hehe,

i could let this one slide, go back another time,


#6

You are missing a close curly bracket just before the line you are seeing the error on.

So your code should be like this

    // clear the answer field
    [answerField setText:@"???"];
}

-(IBAction)showAnswer:(id)sender
{

That and you have an extra close curly at just before the @end so you’ll need to remove that.