It is a bug in the GCC 4.2 frontend, also reproducible in LLVM-GCC 4.2. Congratulations! These compilers have problems in property assignments using dot syntax when the value being assigned is an expression resulting from the conditional operator.
The following code reproduces the problem and shows two source code solutions: one, as you’ve noticed, is to use a temporary variable. The other solution is to use traditional Objective-C message sending syntax instead of dot syntax:
#import <Foundation/Foundation.h>
CGRect CGRectFromString(NSString *string);
@interface SomeClass : NSObject
@property (nonatomic, assign) CGRect frame;
@end
@implementation SomeClass
@synthesize frame;
@end
int main(void) {
NSDictionary *info;
SomeClass *interaction;
NSString *kInteractionFrameKey;
CGRect rect;
rect = [info objectForKey:kInteractionFrameKey] ? CGRectFromString([info objectForKey:kInteractionFrameKey]) : CGRectZero;
interaction.frame = rect;
[interaction setFrame:([info objectForKey:kInteractionFrameKey] ? CGRectFromString([info objectForKey:kInteractionFrameKey]) : CGRectZero)];
interaction.frame = ([info objectForKey:kInteractionFrameKey] ? CGRectFromString([info objectForKey:kInteractionFrameKey]) : CGRectZero);
interaction.frame = ([info objectForKey:kInteractionFrameKey] ? CGRectZero : CGRectFromString([info objectForKey:kInteractionFrameKey]));
interaction.frame = ([info objectForKey:kInteractionFrameKey] ? CGRectZero : CGRectZero);
return 0;
}
Testing with different compilers yields the following:
$ llvm-gcc -c test.m
test.m: In function ‘main’:
test.m:24: error: assignment of read-only variable ‘prop.76’
test.m:25: error: assignment of read-only variable ‘prop.77’
test.m:26: error: assignment of read-only variable ‘prop.78’
$ clang -c test.m
$
You can either use LLVM or avoid dot syntax in that particular case. You might want to file a bug but I wouldn’t hold my breath since Apple isn’t likely to update GCC.