Last active
June 25, 2017 11:26
-
-
Save bennokress/8592e5a7d6b11f31e5eaf9998348035e to your computer and use it in GitHub Desktop.
Extensions for Swift's Int Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Int { | |
static func random(between min: Int, and max: Int) -> Int { | |
return min + Int(arc4random_uniform(UInt32(max - min + 1))) | |
} | |
/// Returns the digits in self | |
var digits: Int { | |
return self.abs < 10 ? 1 : 1 + (self / 10).digits | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment