[swift-users] Cannot invoke 'stride' with an argument list of type '(from: Int, to: Int, by: Int)'
Adriano Ferreira
adriano.ferreira at me.com
Mon Jul 4 22:41:44 CDT 2016
Hi everyone!
I’m converting some code to Swift 3 and got this issue?
Does anybody know what’s going on?
Here’s the code, before and after conversion:
// Swift 2.2
extension Int {
// Repeat a block of code from `self` up to a limit
func up(to upper: Int, by step: Int = 1, @noescape closure: () -> Void) {
for _ in self.stride(to: upper, by: step) {
closure()
}
}
}
// Swift 3
extension Int {
// Repeat a block of code from `self` up to a limit
func up(to upper: Int, by step: Int = 1, _ closure: @noescape () -> Void) {
for _ in stride(from: self, to: upper, by: step) {
closure()
}
}
}
// Usage
1.up(to: 10, by: 2) {
print("Hi!")
}
Best,
— A
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160704/a5308ba6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2016-07-04 at 11.30.45 PM.png
Type: image/png
Size: 54973 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160704/a5308ba6/attachment.png>
More information about the swift-users
mailing list