Principiante luchando con 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?


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;



preguntado el 30 de junio de 12 a las 20:06

The quoted line is fine. The problem has to be elsewhere. Is your header file correct? -

@DrummerB I've added the header :) -

@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) -

Might want to join about 10,000 other noobies on Objective-C with Stanford's iTunes U class called Coding Together -

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. -

1 Respuestas

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.


Remove the dealloc method entirely


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

Respondido el 30 de junio de 12 a las 20:06

That's not going to fix the problem line. It'll only fix the dealloc method. - RonLugge

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

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 - JTApps

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

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 - JTApps

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.