psx
psx

Reputation: 4048

Beginner struggling with Objective-C

I'm following an objective-c book (objective-c fundamentals by Fairbairns, Fahrenkrug, Ruffenach), and I've fallen at the first hurdle with their CoinToss example.

I'm getting an 'expression expected' error on this line:

result.text = coinLandedOnHeads ? @"Heads" : @"Tails";

I have also included a screenshot of the whole page below. What exactly is the problem? I've checked and double checked the code is the same as the book, but have I missed something very obvious?

Thanks!

xcode window

EDIT: Here is my header file:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    UILabel *status;
    UILabel *result;
}

@property (nonatomic, retain) IBOutlet UILabel *status;
@property (nonatomic, retain) IBOutlet UILabel *result;

-(IBAction)callHeads;
-(IBAction)callTails;

@end

Upvotes: 4

Views: 1922

Answers (1)

Jtaylorapps
Jtaylorapps

Reputation: 5770

I know your problem exactly.

The book is outdated. When you created the project you had the tick box 'Automatic reference counting' selected. That means, you don't have to do the dealloc. It's not your fault, Xcode just has a new automatic memory management capability, and the book is old enough so that it's making you do it manually.

To fix it:

Remove the dealloc method entirely

Or,

Restart your project and don't tick the 'Automatic Reference Counting' tick box.

Upvotes: 2

Related Questions