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 { | |
/// SwiftRandom extension | |
static func random(lower: Int = 0, _ upper: Int = 100) -> Int { | |
return lower + Int(arc4random_uniform(UInt32(upper - lower + 1))) | |
} | |
var array: [Int] { | |
return description.characters.map{Int(String($0)) ?? 0} | |
} | |
} |
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 TimeInterval { | |
// builds string in app's labels format 00:00.0 | |
func stringFormatted() -> String { | |
var miliseconds = self.roundTo(places: 1) * 10 | |
miliseconds = miliseconds.truncatingRemainder(dividingBy: 10) | |
let interval = Int(self) | |
let seconds = interval % 60 | |
let minutes = (interval / 60) % 60 | |
return String(format: "%02d:%02d.%.f", minutes, seconds, miliseconds) | |
} |
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 UIColor { | |
/// Format: 0xFFAACC | |
convenience init(hex: Int) { | |
let components = ( | |
R: CGFloat((hex >> 16) & 0xff) / 255, | |
G: CGFloat((hex >> 08) & 0xff) / 255, | |
B: CGFloat((hex >> 00) & 0xff) / 255 | |
) | |
self.init(red: components.R, green: components.G, blue: components.B, alpha: 1) |
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 Date { | |
/// For application labels | |
func toStringAppFormatted() -> String { | |
let components = NSCalendar.current.dateComponents([Calendar.Component.day, | |
Calendar.Component.month, | |
Calendar.Component.year], | |
from: self) | |
return "\(components.day!).\(components.month!).\(components.year!)" | |
} |
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 UIViewController { | |
func showAlert(message: String) { | |
let alert = UIAlertController(title: "Message", message:message, preferredStyle: UIAlertControllerStyle.alert) | |
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler:{ (ACTION :UIAlertAction!)in | |
debugPrint("User click Ok button") | |
})) | |
self.present(alert, animated: true, completion: nil) | |
} | |
} |
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 String { | |
///For placeholders | |
static func randomAlphaNumericString(length: Int) -> String { | |
let charactersString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
let charactersArray : [Character] = Array(charactersString.characters) | |
var string = "" | |
for _ in 0..<length { | |
string.append(charactersArray[Int(arc4random()) % charactersArray.count]) |
NewerOlder