Skip to content

Instantly share code, notes, and snippets.

@hipertracker
Created July 17, 2014 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hipertracker/c8adcdf58f10bfd3c194 to your computer and use it in GitHub Desktop.
Save hipertracker/c8adcdf58f10bfd3c194 to your computer and use it in GitHub Desktop.
Problem with extension
extension Int {
func times(block: () -> ()) {
for _ in 0..self { block() }
}
func times(block: (Int) -> ()) -> Int {
for i in 0..self { block(i) }
return self
}
}
3.times { println("welcome") }
4.times { i in println("by \(i)") } // => Ambigious use of 'times'
@hipertracker
Copy link
Author

// fix:

4.times { (i:Int) in println("by \(i)") }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment