Blog's from the Bush
The ramblings of a lost technocrat...

Obj-C 2.0 Error Msg decoded #1

| No TrackBacks | Bookmark and Share

This is another one of those tips - that are posted here as much for you as for me.

Obj-C brought with it a range of useful and time saving advances to the language. The most widely used amongst these are @property and @synthesize - if you want to know more about them follow the links. This is actually about an Error Msg you can get through forgetting some basics.

The error message in question is this clear piece of literature:

error: synthesized property 'X-Factor' must either be named the same as a compatible ivar or must explicitly name an ivar

Wow - what a mouthful - as Jinx would say.

Here's a very cut down example that would give the error message in question

@interface MyClass : NSObject

{

}

@property (readwrite) BOOL X-Factor;

@end

@implementation MyClass

@synthesize X-Factor;

@end

Short huh? Can you see what the problem is - hopefully it's obvious in this example with all the other extraneous code cut away.

Our interface block (typically in the your ".h" header file) defines a property for the compiler called X-Factor and the implementation block (typically in your ".m" class file) directs the compiler to synthesize (ie. create) the setter and getter methods for an iVar called X-Factor.

Hang on though - our code block doesn't actually declare an iVar now does it? So, does the error message make a bit more sense to you?
Personally I think the error message could be re-written as:
error: No matching declaration in Interface block for synthesized property 'X-Factor'

To fix of course, our interface block needs this line added to it:

BOOL X-Factor;

There you go all fixed!

No TrackBacks

TrackBack URL: http://www.lensenergy.com/cgi-bin/mt/mt-tb.cgi/116

About the Author

 I've been described as a lost technocrat or a wondering luddite, personally I just like everything that takes us forward.


As the principal of CPPL I try to deliver OSS web solutions to our clients and Cocoa platform software for end-users and businesses alike. Oh, and we enjoy writing iPhone software.

Tweets

GetUp! Australia

Pages

Powered by Movable Type 4.33-en

About this Entry

This page contains a single entry by craig published on January 14, 2009 11:01 PM.

Find recent content on the main index or look in the archives to find all content.