Why this works:
- (void) setupInteraction:(IBITSInteraction*)interaction withInfo:(NSDictionary*)info
{
CGRect rect = ([info objectForKey:kInteractionFrameKey] ? CGRectFromString([info objectForKey:kInteractionFrameKey]) : CGRectZero);
interaction.frame = rect;
...
}
and why this doesn’t?:
- (void) setupInteraction:(IBITSInteraction*)interaction withInfo:(NSDictionary*)info
{
interaction.frame = ([info objectForKey:kInteractionFrameKey] ? CGRectFromString([info objectForKey:kInteractionFrameKey]) : CGRectZero);
...
}
I think is exactly the same…
- Compiler: LLVM GCC 4.2
- Error (second case): Assignment of read-only variable ‘prop.283’
- Property frame:
@property (nonatomic, assign) CGRect frame;with its respective@synthesize
Thanks in advance.
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:
Testing with different compilers yields the following:
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.