这是什么意思:NSString * string = NO? @“aaa” :@“bbb”; [英] What does this mean: NSString *string = NO ? @"aaa" : @"bbb";

查看:161
本文介绍了这是什么意思:NSString * string = NO? @“aaa” :@“bbb”;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读Dropbox API,发现这行:

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?

推荐答案

这是一个所谓的三元运算符

C中的三元运算符具有以下模式 condition? true-expression:false-expression

Ternary operators in C have the following pattern condition ? true-expression : false-expression.

如果 condition $ c> YES ,则 true-expression 得到计算,否则 false-expression

If condition evaluates to YES, then true-expression gets evaluated, otherwise false-expression.

在您的特殊情况下, title 会被分配给 @Unlink Dropbox code>如果 [[DBSession sharedSession] isLinked] 返回 YES ,否则 @ Link Dropbox

In your particular case title would get assigned to @"Unlink Dropbox" if [[DBSession sharedSession] isLinked] returns YES, otherwise @"Link Dropbox".

这篇关于这是什么意思:NSString * string = NO? @“aaa” :@“bbb”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆