我想检查NSComparisonResult是否小于等于iOS
。
1。
NSComparisonResult result = blabla...;
if (result == NSOrderedAscending || result == NSOrderedSame) {...}
2。
NSComparisonResult result = blabla...;
if (result <= NSOrderedSame) {...}
我可以使用选项1,但是可以使用选项2吗?我设计它是因为
NSComparisonResult
只是NSInteger
; NSOrderedSame
为0,NSOrderedAscending
为-1,NSOrderedDescending
为1。
最佳答案
如果您小心一点,选项2可能会起作用。目前尚不清楚<=
与>=
的含义,因此令人困惑。对enum
值进行任何假设都不理想。
选项3是更好的选择:
NSComparisonResult result = ...
if (result != NSOrderedDescending) {
// It's either ascending or same
}
关于ios - 我可以对NSComparisonResult使用'> ='吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37494806/