ios - 我可以对NSComparisonResult使用'> ='吗?

标签 ios objective-c

我想检查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/

相关文章:

iphone - 在 iOS 中生成范围内的随机数?

ios - 想要将时间戳添加到居中对齐 textview 并将标签调整为右对齐

objective-c - 使用 TCP/IP 与设备通话

iphone - 如何将像素转换为CGFloat?

ios - 使用本地 CocoaPods pod 编译错误

ios - iOS 7 和 iOS 6 中 UIPickerview 选择器值的默认字体名称和大小是多少

iphone - 我的 NSUserDefaults 加载操作有什么问题吗?

ios - 当用户点击或滚动 UITableView 时如何取消功能?

ios - 未调用自定义 UITableViewCell didSelectRowAtIndexPath

ios - 按钮方向问题