IPhone Obj-C error: assigning variable "prop.149" read-only in Xcode

I am programming an iPhone application using Objective-C.

Here the Xcode error gives me:

error: assignment of read-only variable 'prop.149' 

Code:

 // Create CATransition object CATransition *transition = [CATransition animation]; // Animate over 3/4 of a second transition.duration = 0.75; // using the ease in/out timing function transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; // Set transition type transition.type = kCATransitionPush; // Next line gives error: assignment of read-only variable 'prop.149' transition.subtype = (flipsideView.hidden == YES ? kCATransitionFromRight : kCATransitionFromLeft); 

What does the error mean, and how to fix it?

+4
source share
4 answers

I don’t know exactly why, but the compiler cannot deduce the estimated type of the result of the ternary operator. Just adding an explicit cast seems to work:

 transition.subtype = (NSString *)(flipsideView.hidden == YES ? kCATransitionFromRight : kCATransitionFromLeft); 

I would put this as a compiler error.

+7
source

An error means that you are setting a read-only property. It seems that the CATransition subtype property is not a custom property.

0
source

I agree that the documentation states that you should assign a value to the subtype property. I wonder if there is a problem with your line of code that assigns a subtype. Are you burned by operator priority? Try the following:

 transition.subtype = flipsideView.hidden ? kCATransitionFromRight : kCATransitionFromLeft; 
0
source

This source code does not work:

 transition.subtype = (flipsideView.hidden == YES ? kCATransitionFromRight : kCATransitionFromLeft); 

But it works:

 if (flipsideView.hidden == YES) { transition.subtype = kCATransitionFromRight; } else { transition.subtype = kCATransitionFromLeft; } 
0
source

All Articles