我有一个函数,用于upperBound of closedRange作为一个符合BinaryInteger的for循环,就像我在代码中看到的那样,我只是尽可能地把所有的事情都做好了,但是xCode犯了这个错误,我不知道如何解决它!
错误:
Protocol 'Sequence' requires that 'V.Stride' conform to 'SignedInteger'my函数:
func test<V: BinaryInteger>(value: V) {
if (value >= 0) {
for index in 0...value {
print(index)
}
}
}发布于 2021-07-10 12:21:41
您必须明确地告诉斯威夫特,泛型V表示的“值”可以在for in循环中使用。
func test<V: BinaryInteger>(value: V) where V.Stride:SignedInteger {
if (value >= 0) {
for index in 0...value {
print(index)
}
}
}https://stackoverflow.com/questions/68327503
复制相似问题