swift - 如何将 bool 值与数组进行比较? - swift

标签 swift

我有这个:

if sender.tag == 1 || sender.tag == 2 || sender.tag == 3 || sender.tag == 4 || sender.tag == 5 || sender.tag == 6 || sender.tag == 7 || sender.tag == 8 || sender.tag == 9 || sender.tag == 10 {

无论如何,有没有类似这样的东西来最小化它:

if sender.tag == [1 || 2 || 3 || 4 || 5 || 6 ||  7 || 8 || 9 || 10] {

最佳答案

怎么样

if (1...10).contains(sender.tag)

?

关于swift - 如何将 bool 值与数组进行比较? - swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53644295/

相关文章:

ios - 使用图表框架。 swift 2.0

ios - 显示来自 Core Data ManagedObjectContext 的属性

ios - 'screen' 的 Setter 在 iOS 13.0 中被弃用

swift - 如何在 Swift 中连接蓝牙 sim808

ios - UIView 与 UITableView 作为 subview

ios - 编辑点击的 CollectionViewCell

ios - 数组索引的 NSUserDefaults 对象应该是什么格式

ios - UILongPressGestureRecognizer 无法识别 .ended 状态

swift - 在 swift 中单击时更新行的属性

swift - Swift If 语句中的错误