简体   繁体   English

类型HalfOpenInterval <T> 不符合协议BooleanType

[英]Type HalfOpenInterval<T> does not conform to protocol BooleanType

I have a very simple for loop that is giving me troubles. 我有一个非常简单的for循环,这给我带来了麻烦。 This code ran without issue in Xcode beta 4, but in beta 5 it is complaining that the half open interval (and the closed interval) don't conform to BooleanType. 这段代码在Xcode beta 4中运行没有问题,但是在beta 5中,它抱怨说半开间隔(和关闭间隔)不符合BooleanType。 What has changed, why doesn't this work anymore, or is this a bug? 发生了什么变化,为什么现在不起作用了,或者这是一个错误?

for let i = 0; i..<cellCount!; ++i {
    //do stuff
}

cellCount is defined as an optional Int property: cellCount定义为可选的Int属性:

private var cellCount: Int?

I have tried storing the cellCount into a non-optional constant but the issue still remains: 我尝试将cellCount存储到一个非可选常量中,但问题仍然存在:

let numberOfCells: Int = cellCount!
for let i = 0; i..<numberOfCells; ++i {
    //do stuff
}

I see in the Release Notes a lot has changed with Ranges, but nothing seems to be relevant to this issue. 我在发行说明中看到Ranges发生了很多变化,但似乎与该问题无关。

Ranges are meant to be used in a for in loop: 范围应在for in循环中使用:

for i in 0..<cellCount! {
    // do stuff
}

Does this have anything to do with HalfOpenInterval? 这与HalfOpenInterval有关系吗? I thought the struct is Range? 我以为结构是范围? If you use HalfOpenInterval in for-in, it will not work. 如果在for-in中使用HalfOpenInterval,它将无法正常工作。 It is not of protocol SequenceType 它不是协议SequenceType

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 游乐场执行失败: <EXPR> :15:33:错误:类型&#39;Int&#39;不符合协议&#39;BooleanType&#39; - Playground execution failed: <EXPR>:15:33: error: type 'Int' does not conform to protocol 'BooleanType' 类型&#39;AnyObject&#39;不符合协议&#39;SequenceType&#39; - Type 'AnyObject' does not conform to protocol 'SequenceType' 为什么 c++(和大多数其他语言)同时具有“for”和“while”循环?/你可以用一种类型做什么而你不能用另一种类型做什么? - Why does c++(and most other languages) have both 'for' and 'while' loops?/What can you do with one type that you can't with the other? 如何使一个来自REST服务的另一个数组与一个数组一致? - How to conform an array from another array that comes from a REST Service? 我的函数中的循环不会改变我的数据类型(在 R 中) - The Loop in My Function does not change my data type (in R) 为什么编译器需要尾随返回类型? - Why does the compiler want a trailing return-type? 协议一致性检查是否存在循环? - Protocol conformance check in for loop? 为什么 for(T t : this) 起作用,它是什么意思? - Why does for(T t : this) work and what does it mean? 为什么此代码卡住了并且不起作用(javascript) - Why does this codes stuck and doesn't work (javascript) 查找非重复元素。代码不打印任何内容 - finding non repeating element.Code Does't print anything
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM