In Swift 3, func stride<T : Strideable <apple-reference-documentation://hsYF4ATMnE>>( from start: T, to end: T, by stride: T.Stride) -> StrideTo <apple-reference-documentation://hs9b7RwjpY><T>
Int does not conform to Strideable. Adopted By CGFloat Decimal Double Float Float80 String.UTF16View.Index UnsafeMutablePointer UnsafePointer In Swift 2.2, @warn_unused_result func stride(to *end*: Self, by *stride*: Self.Stride) -> StrideTo <file:///Users/zhaoxin/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.OSX.docset/Contents/Resources/Documents/documentation/Swift/Reference/Swift_StrideTo_Structure/index.html#//apple_ref/swift/struct/s:Vs8StrideTo> <Self> It uses Self, which means the type of the variable, instead of T. Zhaoxin On Tue, Jul 5, 2016 at 11:41 AM, Adriano Ferreira via swift-users < [email protected]> wrote: > 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 > > _______________________________________________ > swift-users mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-users > >
_______________________________________________ swift-users mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-users
