Build failed


#1

I cannot build the first example.

I don´t know how to replace the placeholders

Compiler complains about ‘expected expression’

@implementation Quiz2ViewController

- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{
  
  
  // call super init
  
  self = [super initWithNibName:<#nibNameOrNil#> bundle:<#nibBundleOrNil#>];
  if (self) {
    
    questions = [[NSMutableArray alloc] init];
    answers = [[NSMutableArray alloc] init];
    
    [questions = addObject:@"What is 7 + 7?"];
    [answers addObject:@"14"];
    
  }
  
     return self;
     
}

- (IBAction)showQuestion:(id)sender
{
  
  
}

- (IBAction)showAnswer:(id)sender
{
  
}

@end

#2
self = [super initWithNibName:<#nibNameOrNil#> bundle:<#nibBundleOrNil#>];

In Xcode, the words surrounded by <# #> will appear with a blue oval around them. Delete them and type in the same text that is there.


#3

Hello,

thank you for your answer.

I have ‘copy’ and ‘paste’ the line from xcode into the editor…
self = [super initWithNibName:<#nibNameOrNil#> bundle:<#nibBundleOrNil#>];

In xcode the line is exactly as printed in the book

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

The code does not compile.

By the way. I downloaded the ‘solutions’ from your Website.

The ‘Quiz’ code has nothing to do with the printed code? ‘QuizViewController.m’ is dated 30th August 2011?

Still not able to run the example.

Can you upload the actual code to the Website? I think it will help others too.

Best regards


#4

Oops, you are right, the solution for the first chapter isn’t on the website. We’ll get on that.

As for your problem, you have to understand that even though the line appears the same in the book, there is extra markup that allows Xcode to show code completion placeholders. Try typing in that entire line again, but not letting the code-completion finish it for you.


#5

we have the same problem before mate, just retype them LETTER by LETTER. :slight_smile: Follow what mr.conway said,


#6

I have the same problem, but with this error:

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

Cannot assign to ‘self’ outside of a method in the init family

What does this mean?


#7

Where did you put self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; ?
You probably put it in a method that’s not an initializer.

Here is a similar problem:

//  main.m

#import <Foundation/Foundation.h>

@interface IT: NSObject
- (id)init;
- (void)junk:(id)object;
@end

int main (int argc, const char * argv[])
{
    IT *it = [[IT alloc] init];
    [it junk:nil];
    return 0;
}

@implementation IT

- (id)init
{
    self = [super init];  // okay here
    return self;
}

- (void)junk:(id)object
{
    self = [super init];  // can't do this here
}
@end

#8

No, just followed the book…

  • (id)initwithNibName: (NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
    //call the init method implemented by the super class

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if(self) {


#9

Here is the culprit: - (id)[color=#FF0000]initwith[/color]NibName: (NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

The method name should be - (id)initWithNibName: (NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

Just change [color=#FF0000]initwith[/color] to initWith

Whenever you can, try copying and pasting the method names from the Apple’s documentation or turn on auto-completion in Xcode’s editor.


#10

Thank you, I should have seen it. I was misled by the error being flagged in the code, and not the declaration.


#11

[quote=“ibex10”]Here is the culprit: - (id)[color=#FF0000]initwith[/color]NibName: (NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

The method name should be - (id)initWithNibName: (NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

Just change [color=#FF0000]initwith[/color] to initWith

Whenever you can, try copying and pasting the method names from the Apple’s documentation or turn on auto-completion in Xcode’s editor.[/quote]

I had not this special w/W issue. I used auto-completion and the code is exactly the same as in the book on page 84. Build fails. There is an error in the line “self =” with the message “Expected expression”. There is an arrow pointing to the space before “bundle:”


#12

[quote=“platypus”][quote=“ibex10”]Here is the culprit: - (id)[color=#FF0000]initwith[/color]NibName: (NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

The method name should be - (id)initWithNibName: (NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

Just change [color=#FF0000]initwith[/color] to initWith

Whenever you can, try copying and pasting the method names from the Apple’s documentation or turn on auto-completion in Xcode’s editor.[/quote][/quote]

I had not this special w/W issue. I used auto-completion and the code is exactly the same as in the book on page 84. Build fails. There is an error in the line “self =” with the message “Expected expression”. There is an arrow pointing to the space before “bundle:”.

Finally I found the solution in the placeholders’ issue (see page 18). I deleted the rounded rectangles and typed in the same text again. Now no errors.
Thanks!


#13

My build failed. The issue occurred in QuizViewController.m

ARC Issue
No visible @interface for ‘NSMutableArray’ declares the selector ‘objectAtindex.’

I looked it over several times and I think I have it typed in as shown in the book, but…


#14

chipdawg:

You need to include your code between the Code tags so that we can look over what it is you’ve got typed. Then I’m sure someone will be able to point you in the right direction.


#15

Well I found it. I will post it anyway in case in may help someone else:[code]#import “QuizViewController.h”

@interface QuizViewController ()

@end

@implementation QuizViewController

  • (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
    // Call the init method implemented by the superclass
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    // Create two arrays and make the pointer point to them
    questions = [[NSMutableArray alloc] init];
    answers = [[NSMutableArray alloc] init];

      // Add questions and answers to the arrays
      [questions addObject:@"What is 7 + 7?"];
      [answers addObject:@"14"];
      
      
      [questions addObject:@"What is the capitol of Vermont?"];
      [answers addObject:@"Montpelier"];
      
      
      [questions addObject:@"From what is cognac made?"];
      [answers addObject:@"Grapes"];
    

    }

    //Return the address of the new object
    return self;
    }

  • (IBAction)showQuestion:(id)sender
    {
    // Step to the next question
    currentQuestionIndex++;

    // Am I past the last quetion?
    if (currentQuestionIndex == [questions count]) {

      // Go back to the first question
      currentQuestionIndex = 0;
    

    }

    //Get the string at the index in the questions array
    NSString *question = [questions objectAtIndex:currentQuestionIndex];

    //Log the string to the console
    NSLog(@“displaying question: %@”, question);

    // Display the string in the question field
    [questionField setText];

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

  • (IBAction)showAnswer:(id)sender
    {
    // What is the answer to the current question?
    NSString *answer = [answers objectAtindex:currentQuestionIndex];

    // Display it in the answer field
    [answerField setText:answer];
    }

@end
[/code]
The ARC Issue is in the line:

NSString *answer = [answers objectAtindex:currentQuestionIndex];

   I put a lower-case i in objectAtindex and it should have been a capitol I objectAtIndex.  Sorry for the fuss

#16

[quote=“platypus”][quote=“platypus”][quote=“ibex10”]Here is the culprit: - (id)[color=#FF0000]initwith[/color]NibName: (NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

The method name should be - (id)initWithNibName: (NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

I had not this special w/W issue. I used auto-completion and the code is exactly the same as in the book on page 84. Build fails. There is an error in the line “self =” with the message “Expected expression”. There is an arrow pointing to the space before “bundle:”.

Finally I found the solution in the placeholders’ issue (see page 18). I deleted the rounded rectangles and typed in the same text again. Now no errors.
Thanks![/quote][/quote][/quote]

I had this exact same problem. I let XCode auto-complete the - (id)initWithNibName: (NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil line. Even though the text reads properly, XCode must see it differently. I had to delete the nibNameOrNil and nibBundleOrNil and retype them as well. Works fine after that.


#17

Which is explicitly stated on the next page of the book!

“Placeholders are not valid code, and you have to replace them to build the application. This can be confusing because placeholders often have the same names that you want your argument to have.”

Thats what I get for jumping ahead :blush:


#18

Can anyone help me with this:

#import “QuizViewController.h”

@implementation QuizViewController (Incomplete implementation error*)

  • (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
    {
    //Call the init method implemented by the superclass
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    //Create two arrays and make the pointers point to them
    questions = [[NSMutableArray alloc] init];
    answers = [[NSMutableArray alloc] init];

      //Add questions and answers to the arrays
      [questions addObject:@"What is 7 + 7?"];
      [answers addObject:@"14"];
      
      [questions addObject:@"What is the capital of Ireland"];
      [answers addObject:@"Dublin"];
      
      [questions addObject:@"From what is wine made?"];
      [answers addObject:@"Grapes"];
    

    }
    //Return the address of the new object
    return self;
    }

  • (IBAction)showQuestion:(id)sender; (Expected expression error)
    {
    //Step to the next question
    currentQuestionIndex++;

    //Am I past the last question?
    if (currentQuestionIndex== [questions count]) {
    //Go back to the first question
    currentQuestionIndex = 0;
    }
    //Get the string in that index in the questions array
    NSString *question = [questions objectAtIndex:currentQuestionIndex];

    //Log the string to the console
    NSLog(@“Displaying question: %@” , question);

    //Display the string in the question field
    [questionfield setText];

    //Clear the answer field
    [answerfield setText:@"???"];

    • (IBAction)showAnswer:(id)sender;
      {
      //What is the answer to the current question?
      NSString *answer = [answers objectAtIndex: currentQuestionIndex];

      //Display it in the answer field
      [answerfield setText:answer];
      }
      }


#19

Double check the end of your -showAction: method. You have two braces.

}
}

Move one of those up above the line:

- (IBAction)showAction:(id)sender {

The way you have it written, the compiler doesn’t see an endpoint of your -showQuestion: method


#20

Also, I’m not sure if the compiler cares about this issue, but you don’t need a semicolon in the first line of your method definitions.

You have this:

- (IBAction)someMethod:(id)sender;
{

And all you need is this:

- (IBAction)someMethod:(id)sender
{