views:

172

answers:

1

This might be iPhone specific, I'm not sure. The compiler doesn't complain when building for the simulator but when compiling for device it throws some funky errors when I try to set properties for references to objects. Eg,

@property (nonatomic) CGRect  &finalFrame;

and the coressponding synthesizer

@synthesize finalFrame;

for a variable declared as

CGRect finalFrame;

Gives the errors

  • type of property 'finalFrame' does not match type of ivar 'finalFrame'
  • Unrecognisable insn:
  • Internal compiler error: Bus error
  • Internal compiler error: in extract_insn, at recog.c:2904

However I can do it manually without issue, with the following methods:

- (CGRect&)finalFrame;
- (void)setFinalFrame:(CGRect&)aFrame;

Is this a gcc bug? It does compile for the simulator.

+3  A: 

Your property is declared as a reference type (CGRect&) but your instance variable is not a reference type (CGRect). They need to be the same to use @synthesize.

Also, it's a little weird to be using C++ reference types as Objective-C properties, but I guess that might work as long as all the files are being compiled as Objective-C++.

Kristopher Johnson
Sam
I mean I understand that the property expects the same datatype as the variable, but surely it is a bug in the mechanism if it cannot cope with references? Perhaps I am missing some fundamental understanding of properties, because I always thought they were essentially preprocessed into methods such as the ones I posted.
Sam
@Sam: To say it's preprocessed into methods isn't correct. The `@synthesize` directive causes methods to be generated, but it's not dumb text replacement like a preprocessor macro. The compiler has to match the types up in order to generate the appropriate method, and apparently it doesn't understand references well enough to generate the appropriate method tying a reference to a normal datatype. I suppose you could call it a bug, though actually it's just something that isn't supported.
Chuck
Thanks Chuck. Accepting this as answer
Sam