Skip to content

Instantly share code, notes, and snippets.

@gchriswill
Last active August 29, 2015 14:24
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 gchriswill/f273a09cc98726dc651f to your computer and use it in GitHub Desktop.
Save gchriswill/f273a09cc98726dc651f to your computer and use it in GitHub Desktop.
Extends Swift's Array structure by providing stepping functionality recursively using an external variable.
// Created on 6/2/15 by Christopher Gonzalez D.K.A. @gchriswill https://github.com/JWShroyer
// Reviewed and optimyzed by Josh Shroyer D.K.A @JWShroyer https://github.com/JWShroyer
// Last revision on 7/11/15 by @gchriswill and @JWShroyer
extension Array {
mutating func countForward(inout counter c: Int) -> Void {
var s = self.count - 1
c = c < s && !(0 > c) ? (c + 1) : 0
}
mutating func countBackward(inout counter c: Int) -> Void {
var s = self.count - 1
c = 0 >= c || c > s ? s : (c - 1)
}
}
@gchriswill
Copy link
Author

@JWShroyer, Here is the gist.
The protocol version will be uploaded through a separate file in this repository... 👾

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