- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下功能:
private func randomName<T: Object & TextName>(from results: Results<T>, crossNameChance: Int, textRanges: [[CountableRange<Int>]]?) -> String
如果我通过 nil
就可以正常工作对于 textRanges
,但是它会生成一个错误:
Argument passed to call that takes no arguments
当我通过时:
[[0...1], [2...3], [1...1, 3...3], [0...0, 2...2]]
作为 textRanges
的参数
我在这里做错了什么?
最佳答案
语法a...b
返回 CountableClosedRange
,这是与 CountableRange
不同的类型。要么将参数更改为 textRanges: [[CountableClosedRange<Int>]]?
,或将每个间隔更改为 a..<b
的形式.
您可以通过分解您尝试作为参数传递的值来解决这个问题:
let textRanges: [[CountableRange<Int>]]? = [[0...1], [2...3], [1...1, 3...3], [0...0, 2...2]]
将为您提供更有用的错误消息:
error: cannot convert value of type 'CountableClosedRange<Int>' to expected element type 'CountableRange<Int>'
关于Swift:CountableRange<Int> 数组:传递给不带参数的调用的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48629998/
我有以下功能: private func randomName(from results: Results, crossNameChance: Int, textRanges: [[Countable
这个问题在这里已经有了答案: Cannot invoke initializer for type 'Range' with an argument list of type '(Range)' (
let range = 3..<3 // lowerBound == upperBound Swift 标准库在多个地方使用这种类型的范围,例如在数组 insert(_, at:) 中方法。 Arra
Documentation says : The associated Bound type is both the element and index type of CountableRange.
错误:无法使用 CountableRange 类型的索引为 Array 类型的值添加下标 我想从任何数组/序列中找到一些顶级元素。 extension Array { func top(max
我是一名优秀的程序员,十分优秀!