我正在进行泛型编程,并拥有符合Integer的内容。不知何故,我需要将其转换为一个具体的Int以便使用。
extension CountableRange
{
// Extend each bound away from midpoint by `factor`, a portion of the distance from begin to end
func extended(factor: CGFloat) -> CountableRange<Bound> {
let theCount = Int(count) // or lowerBound.distance(to: upperBound)
let amountToMove = Int(CGFloat(theCount) * factor)
return lowerBound - amountToMove ..< upperBound + amountToMove
}
}
这里的错误出在
let theCount = Int(count)
上。具体错误信息是:首先,错误信息可以更有帮助一些,因为Cannot invoke initializer for type 'Int' with an argument list of type '(Bound.Stride)'
CountableRange
将其Bound.Stride
定义为SignedInteger
(source)。所以错误信息本应该告诉我这一点。现在我知道它是一个
整数
,但我该如何实际使用这个整数
值呢?