Reputation: 2161
I was reading over the Dropbox API and I found this line:
NSString* title = [[DBSession sharedSession] isLinked] ? @"Unlink Dropbox" : @"Link Dropbox";
I've never seen that syntax before? What is it called and what does it mean? I can tell what it does just from looking at it but could someone tell me about it?
Upvotes: 0
Views: 336
Reputation: 7633
You can also use this to print BOOL
s values like:
NSLog(@"%@", boolVal ? @"YES" : @"NO");
Upvotes: 2
Reputation: 29552
That is a so-called ternary operator
Ternary operators in C have the following pattern condition ? true-expression : false-expression
.
If condition
evaluates to YES
, then true-expression
gets evaluated, otherwise false-expression
.
In your particular case title
would get assigned to @"Unlink Dropbox"
if [[DBSession sharedSession] isLinked]
returns YES
, otherwise @"Link Dropbox"
.
Upvotes: 12