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]) |
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 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 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 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 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
/// Truncates String to given langth | |
/// | |
/// - Parameter length: Result string will be limited to the given number of characters. | |
/// If length is 0 or less - empty string will be returned | |
/// - Returns: truncated string. | |
func truncateToLength(_ length: Int) -> String { | |
if length <= 0 { | |
// returns empty string | |
return "" | |
} else if length < self.characters.count { |
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
KEYWORDS="TODO|FIXME" | |
echo "searching ${SRCROOT} for ${KEYWORDS} in *.h and *.m files" | |
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$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
# more info: http://stackoverflow.com/questions/24183812/swift-warning-equivalent | |
TAGS="TODO:|FIXME:" | |
echo "searching ${SRCROOT} for ${TAGS}" | |
find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$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
// | |
// AVMetadataItem with utf8 string (eg. Ukrainian, Russian) | |
// | |
import Foundation | |
import AVFoundation | |
extension AVMetadataItem { | |
/// stringValue: ISO-8859-1 → UTF-8 |
OlderNewer