Swift Range on the fly 1...12.contains(1) 无法使用 (Int) 调用 'contains'

标签 swift range

不可能创建一个范围并像这样调用它的 contains 方法:

1...12.contains(1)

当我创建 var range = 1...12并打印它的 dynamicType 我得到一个 Swift.Range<Swift.Int> ,所以我猜这不是类型不匹配问题,是吗?

最佳答案

在这种情况下,问题在于运算符优先级:

(1...12).contains(1)   // -> true

(否则代码看起来确实模棱两可)

关于Swift Range on the fly 1...12.contains(1) 无法使用 (Int) 调用 'contains',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30986505/

相关文章:

python - python 中的范围和 "for loops"?

Python range() 和 zip() 对象类型

perl - 如何打印 Perl 中最后一个数组元素的第一个到第五个?

swift - 从 NSInputStream 读取 IntegerType

json - 调用中存在额外参数 'error'?但我根本没有 'error' 变量?

ios - 调用 dispatch_async(dispatch_get_main_queue()) 时 UIView 屏幕卡住

MySql用户输入限制

ios:将新密码添加到 iCloud 钥匙串(keychain)

ios - 显示在 iOS 应用程序中打开的 PDF 内容 (Swift)

python - 只需要索引 : enumerate or (x)range?