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
enum APIError: Error, LocalizedError { | |
case unknown, apiError(reason: String), parserError(reason: String) | |
var errorDescription: String? { | |
switch self { | |
case .unknown: | |
return "Unknown error" | |
case .apiError(let reason), .parserError(let reason): | |
return reason | |
} |
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 NSMutableAttributedString { | |
var fontSize:CGFloat { return 14 } | |
var boldFont:UIFont { return UIFont(name: "AvenirNext-Bold", size: fontSize) ?? UIFont.boldSystemFont(ofSize: fontSize) } | |
var normalFont:UIFont { return UIFont(name: "AvenirNext-Regular", size: fontSize) ?? UIFont.systemFont(ofSize: fontSize)} | |
func bold(_ value:String) -> NSMutableAttributedString { | |
let attributes:[NSAttributedString.Key : Any] = [ | |
.font : boldFont | |
] |
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
var millisecondsSince1970: Int { | |
return Int(self.timeIntervalSince1970.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
extension UIView { | |
func height(constant: CGFloat) { | |
setConstraint(value: constant, attribute: .height) | |
} | |
func width(constant: CGFloat) { | |
setConstraint(value: constant, attribute: .width) | |
} | |
private func removeConstraint(attribute: NSLayoutConstraint.Attribute) { |
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
/// A little pieve of genius by me that culculates cell size base on the image given while maintaining aspect ratio | |
open class MediaMessageSizeCalculator { | |
open func messageContainerSize(for image: UIImage) -> CGSize { | |
let maxWidth = UIScreen.main.bounds.width - 16 | |
let sizeForMediaItem = { (maxWidth: CGFloat, item: UIImage) -> CGSize in | |
if maxWidth < item.size.width { | |
// Maintain the ratio if width is too great | |
let height = maxWidth * item.size.height / item.size.width | |
return CGSize(width: maxWidth, 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
protocol Dimension { | |
func constraint(equalToConstant c: CGFloat) -> NSLayoutConstraint | |
} | |
protocol Anchor { | |
func constraint(equalTo anchor: Self, constant: CGFloat) -> NSLayoutConstraint | |
func constraint(greaterThanOrEqualTo anchor: Self, constant: CGFloat) -> NSLayoutConstraint | |
func constraint(lessThanOrEqualTo anchor: Self, constant: CGFloat) -> NSLayoutConstraint | |
} |
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
if !UIAccessibilityIsReduceTransparencyEnabled() { | |
view.backgroundColor = .clear | |
let blurEffect = UIBlurEffect(style: .dark) | |
let blurEffectView = UIVisualEffectView(effect: blurEffect) | |
//always fill the view | |
blurEffectView.frame = self.view.bounds | |
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
view.addSubview(blurEffectView) //if you have more UIViews, use an insertSubview API to place it where needed |
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
class ArrayImpl<T> { | |
var space: Int | |
var count: Int | |
var ptr: UnsafeMutablePointer<T> | |
init(count: Int = 0, ptr: UnsafeMutablePointer<T> = nil) { | |
self.count = count | |
self.space = count | |
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
let countries = [ | |
"AF - Afghanistan", | |
"AX - Aland Islands", | |
"AL - Albania", | |
"DZ - Algeria", | |
"AS - American Samoa", | |
"AD - Andorra", | |
"AO - Angola", | |
"AI - Anguilla", | |
"AQ - Antarctica", |
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
let state = [ "AK - Alaska", | |
"AL - Alabama", | |
"AR - Arkansas", | |
"AS - American Samoa", | |
"AZ - Arizona", | |
"CA - California", | |
"CO - Colorado", | |
"CT - Connecticut", | |
"DC - District of Columbia", | |
"DE - Delaware", |
NewerOlder