objective-c - 是缩短的问号冒号吗? : a Objective-C syntax?

标签 objective-c

Xcode 没有给出我的(thought-to-be)打字错误的错误:

 NSString *theme = [[NSUserDefaults standardUserDefaults] objectForKey:@"theme"];
 NSLog(@"Theme: %@", theme ?: @"Default");

事实证明:

 NSLog(@"Theme: %@", theme ?: @"Default");

工作原理与:

 NSLog(@"Theme: %@", theme ? theme : @"Default");

上面的缩短语法是否适用于 gcc only ?或者它是 Objective-C 的一部分?

最佳答案

它是 C 中条件表达式的 GNU 扩展:

来自 here :

A GNU extension to C allows omitting the second operand, and using implicitly the first operand as the second also:

a = x ? : y;

关于objective-c - 是缩短的问号冒号吗? : a Objective-C syntax?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13065196/

相关文章:

ios - 插入 View Controller 时动画出现抖动

objective-c - 在 iOS 上绘制缩放的表情符号图标

ios - 渐变颜色在非英语语言的 UILabel 中被截断

ios - AES128 memcry() 崩溃

iphone - 我怎样才能知道 iPhone 中当前 View Controller 的名称

objective-c - 如何在运行时检查 Mac OS X 版本

ios - 如何设置 UITableViewRowAction 的 Action

ios - objective-c/JSON : How to get ObjectForKey when it's a top level object

c++ - iOS中Opencv人脸检测Cascade编译器报错

ios - Dlpiechart 仅适用于初始 View Controller