4

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
12
  • The quoted line is fine. The problem has to be elsewhere. Is your header file correct?
    – DrummerB
    Jun 30, 2012 at 19:37
  • @DrummerB I've added the header :)
    – psx
    Jun 30, 2012 at 19:39
  • 1
    @psynnott completely salvageable! The language hasn't been changed too much, just new (and USEFUL) features added. If you have the money for it, I'd recommend a more up-to-date book, but if you don't, just remember that retain/release is now handled for you with ARC. (Storyboards is something worth the new book, IMO, but you can probably find tutorials on them out in the wild wild web)
    – RonLugge
    Jun 30, 2012 at 19:43
  • 3
    Might want to join about 10,000 other noobies on Objective-C with Stanford's iTunes U class called Coding Together
    – tarheel
    Jun 30, 2012 at 19:44
  • 2
    You could (while reading the book and learning the basics) make sure that ARC is turned off. That code will still be perfectly fine and run on iPhones and the simulator. Or you could decide to skip (most of the) memory management chapters in your book and learn how to use ARC, which makes these things a lot easier. Though some background knowledge wouldn't hurt either. I recommend watching the '11 and '12 WWDC videos about ARC.
    – DrummerB
    Jun 30, 2012 at 19:47

1 Answer 1

2

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.

8
  • 1
    That's not going to fix the problem line. It'll only fix the dealloc method.
    – RonLugge
    Jun 30, 2012 at 19:44
  • Thanks, I will try creating the project again. I'll update as soon as I tried :) Edit: After reading Ron's comment, I'll await more replies.
    – psx
    Jun 30, 2012 at 19:44
  • Don't loose heart, Objective-C is a tough language, and it's not made any easier by the lack of up-to-date books. I highly recommend the series done by The Big Nerd Ranch on Objective-C. Also, if your code still has trouble, update the screenshot and I'll try to help out again Jun 30, 2012 at 19:46
  • 3
    Instead of recreating the entire project without Automatic Reference Counting, you could also just turn it off in the build settings. Just click on your project and search for the "Objective-C Automatic Reference Counting" option.
    – omz
    Jun 30, 2012 at 19:54
  • 1
    You had some down votes, I up voted to keep you at zero. Sometimes people forget they used to be beginners and had to ask some simple questions Jun 30, 2012 at 19:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.