0

I am starting to program in Objective-C. I am using a book to learn the first basics. The given example is not working! I can not see the problem in my code.
It was not so hard to understand it, but it just won't work. But everything I found elsewhere, they added Objects like I did.
I don't know if the syntax changed? I am using the iOS 4.3 SDK and Xcode 3.2.6!?
This part fails:

[questions addObject: @”What is 7 + 7?”]; //FAILS
[answers addObject: @”14”];

The error message says:
/Applications/Quiz/Classes/QuizAppDelegate.m:32:0
Applications/Quiz/Classes/QuizAppDelegate.m:32: error: expected expression before '@' token

I would be really happy, if someone can help me! Thank you!

I attached the code as well!

Jules

Full code: .h:

#import <UIKit/UIKit.h>

@interface QuizAppDelegate : NSObject <UIApplicationDelegate> {

    int currentQuestionIndex;

    //The model objects
    NSMutableArray *questions;
    NSMutableArray *answers;

    //The view objects
    IBOutlet UILabel *questionField;
    IBOutlet UILabel *answerField;

    UIWindow *window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

-(IBAction)showQuestion:(id)sender;
-(IBAction)showAnswer:(id)sender;

@end

Part code where it fails: .m:

#import "QuizAppDelegate.h"

@implementation QuizAppDelegate

@synthesize window;

-(id)init{

    // Call the init method implemented by the superclass 
    [super init];

    // 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?”]; //FAILS
    [answers addObject: @”14”];

    [questions addObject: @”Was ist die Hauptstadt von Madagaskar?”]; //FAILS
    [answers addObject: @”Antananarivo”];

    [questions addObject: @”Was ergibt 5-2*2+6?”]; //FAILS
    [answers addObject: @”7”];

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

}

-(IBAction)showQuestion:(id)sender{

//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 at 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:question];

//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];
} 
5
  • 3
    I think, you are using the false character for ", as yours is ”. Did you copy and paste the code from somewhere? Commented Sep 28, 2011 at 16:08
  • 1
    He's right. Look at the double-quote in your "NSLog" statements. It's a different (correct) character. Commented Sep 28, 2011 at 16:11
  • @vikingosegundo you should add that as an answer! Commented Sep 28, 2011 at 16:12
  • just did it. First felt like it does only worth to be a comment. But an answer is an answer… Commented Sep 28, 2011 at 16:14
  • @julesmummdry — You don't need to add <br> for a break row. just to blanks and enter is enough. Commented Sep 28, 2011 at 16:20

2 Answers 2

9

I think, you are using the false character for the double quote ", as yours is ”. Did you copy and paste the code from somewhere?

Sign up to request clarification or add additional context in comments.

Comments

-1

Or even shorter:

[myArray addObject:[NSString stringWithString:@"Wie hoch ist der Eiffelturm?"]];

1 Comment

Even shorter (and still functional) is exactly the way he did it! (with corrected quotes of course)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.