This file contains hidden or 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
lazy var v1:UIView = { | |
let v = UIView() | |
v.backgroundColor = .blueColor() | |
return v | |
}() | |
lazy var v2:UIView = { | |
let v = UIView() | |
v.backgroundColor = .blueColor() | |
return v |
This file contains hidden or 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
private func performWithoutAnimation(closureToPerform: () -> Void) { | |
UIView.setAnimationsEnabled(false) | |
closureToPerform() | |
UIView.setAnimationsEnabled(true) | |
} |
This file contains hidden or 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 UIView { | |
var snapshot: UIImage? { | |
UIGraphicsBeginImageContext(self.frame.size) | |
guard let context = UIGraphicsGetCurrentContext() else { | |
return nil | |
} | |
layer.render(in: context) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() |
This file contains hidden or 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
static func mapValuesToQueryItems(values: [String:Any?]) -> [URLQueryItem]? { | |
let returnValues = values | |
.filter { $0.1 != nil } | |
.map { (item: (_key: String, _value: Any?)) -> [URLQueryItem] in | |
if let value = item._value as? Array<String> { | |
return value.map { (v) -> URLQueryItem in | |
URLQueryItem( | |
name: item._key, | |
value: v | |
) |
This file contains hidden or 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 { | |
func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat { | |
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude) | |
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: font], context: nil) | |
return ceil(boundingBox.height) | |
} | |
func width(withConstraintedHeight height: CGFloat, font: UIFont) -> CGFloat { | |
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height) |
This file contains hidden or 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
public extension UIColor { | |
convenience init(hex: Int, alpha: Double = 1.0) { | |
let r = CGFloat((hex & 0xFF0000) >> 16) / 255.0 | |
let g = CGFloat((hex & 0x00FF00) >> 8) / 255.0 | |
let b = CGFloat(hex & 0x0000FF) / 255.0 | |
self.init(red: r, green: g, blue: b, alpha: CGFloat(alpha)) | |
} | |
} |
This file contains hidden or 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
private static var dateFormatter: DateFormatter = { | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateStyle = .medium | |
return dateFormatter | |
}() |
This file contains hidden or 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 { | |
var millisecondsSince1970:Int { | |
return Int((self.timeIntervalSince1970 * 1000.0).rounded()) | |
} | |
init(milliseconds:Int) { | |
self = Date(timeIntervalSince1970: TimeInterval(milliseconds / 1000)) | |
} | |
} |
This file contains hidden or 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
protocol StringType { | |
var isEmpty: Bool { get } | |
} | |
extension String : StringType { } | |
extension Optional where Wrapped: StringType { | |
var isNullOrEmpty: Bool { | |
return self?.isEmpty ?? true | |
} |
This file contains hidden or 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
self.subviews.forEach({ $0.removeFromSuperview() }) |