What does the question mark and the colon (?: ternary operator) mean in objective-c?

This is the C ternary operator (Objective-C is a superset of C): label. Frame = (inPseudoEditMode)? KLabelIndentedRect : kLabelRect is semantically equivalent to if(inPseudoEditMode) { label.

Frame = kLabelIndentedRect; } else { label. Frame = kLabelRect; }.

This is the C ternary operator (Objective-C is a superset of C): label. Frame = (inPseudoEditMode)? KLabelIndentedRect : kLabelRect; is semantically equivalent to if(inPseudoEditMode) { label.

Frame = kLabelIndentedRect; } else { label. Frame = kLabelRect; }.

Uhh that was fast :) Thanks a lot. – rdesign Apr 7 '10 at 19:47 2 (update: Yuck! Reposting as an answer.) What is so important about the ternary operator is that it can be used in places that an if-else cannot.

Ie: Inside a condition or method parameter. NSString stringWithFormat: @"Status: %@", (statusBool? @"Approved" : @"Rejected") ...which is a great use for preprocessor constants: #define statusString (statusBool?

@"Approved" : @"Rejected") ...then: NSString stringWithFormat: @"Status: %@", statusString This saves you from having to use and release local variables in if-else patterns. FTW! – Richard Bronosky May 6 '10 at 15:52.

It's the tertiary operator. It's basic form is: condition? ValueIfTrue : valueIfFalse Where the values will only be evaluated if they are chosen.

Building on Barry Wark's excellent explanation... What is so important about the ternary operator is that it can be used in places that an if-else cannot. Ie: Inside a condition or method parameter. NSString stringWithFormat: @"Status: %@", (statusBool?

@"Approved" : @"Rejected") ...which is a great use for preprocessor constants: // in your pch file... #define statusString (statusBool? @"Approved" : @"Rejected") // in your m file... NSString stringWithFormat: @"Status: %@", statusString This saves you from having to use and release local variables in if-else patterns. FTW!

This is part of C, so it's not Objective-C specific. Here's a translation into an if statement: if (inPseudoEditMode) label. Frame = kLabelIndentedRec; else label.

Frame = kLabelRect.

It's just a short form of writing an in-then-else statement. It means the same as the following code: if(inPseudoEditMode) label. Frame = kLabelIndentedRect else label.

Frame = kLabelRect.

That's just the usual ternary operator. If the part before the question mark is true, it evaluates and returns the part before the colon, otherwise it evaluates and returns the part after the colon. A?

B:c is like if(a) b; else c.

The question mark and the colon means in objective-c (without quotes):. The question mark (?; also known as an interrogation point, interrogation mark, question point, query, or eroteme),1 is a punctuation mark that replaces the full stop (period) at the end of an interrogative sentence in English and many other languages. The question mark is not used for indirect questions.

The question mark character is also often used in place of missing or unknown data.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions