[swift-users] Cannot invoke 'stride' with an argument list of type '(from: Int, to: Int, by: Int)'

Joe Groff jgroff at apple.com
Tue Jul 5 15:14:33 CDT 2016


This is a known bug. The definition of 'stride' inside 'Int' for migration from Swift 2 causes the compiler to fail to find the global function. https://bugs.swift.org/browse/SR-1798

-Joe

> On Jul 4, 2016, at 8:41 PM, Adriano Ferreira via swift-users <swift-users at swift.org> wrote:
> 
> Hi everyone!
> 
> I’m converting some code to Swift 3 and got this issue?
> 
> 
> <Screen Shot 2016-07-04 at 11.30.45 PM.png>
> 
> 
> 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
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list