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/