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 UILabel { | |
static func spaceLabel() -> UILabel { | |
let spacingLabel = UILabel() | |
spacingLabel.frame = CGRect(x: 0, y: 0, width: 150, height: 50) | |
spacingLabel.textColor = .white | |
spacingLabel.textAlignment = .center | |
spacingLabel.font = UIFont.boldSystemFont(ofSize: 18) | |
spacingLabel.text = "LIKE ME" | |
spacingLabel.backgroundColor = .red |
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
import UIKit | |
let imageCache = NSCache<AnyObject, AnyObject>() | |
extension UIImageView { | |
func loadImage(urlString: String) -> Void { | |
if urlString.isEmpty { return } | |
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
import UIKit | |
infix operator |: AdditionPrecedence | |
public extension UIColor { | |
struct App { | |
static let hyperLink = UIColor.colorWithHex(hex: "#FFFFFF") | |
static let background = UIColor.white | UIColor.black | |
} | |
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
import Network | |
class NetworkReachability { | |
static let shared = NetworkReachability() | |
private var monitor: NWPathMonitor? | |
private var isMonitoring = false | |
// use it to notified that monitoring did start. | |
var didStartMonitoringHandler: (() -> Void)? |
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
import Foundation | |
enum NetworkError: Error { | |
case decodingError | |
case domainError | |
case urlError | |
} | |
enum HttpMethod: String { |
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
class BindingTextField: UITextField { | |
var textChangedHandler: (String) -> () = { _ in } | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
initialSetup() | |
} | |
required init?(coder: NSCoder) { |
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
struct Stack<T>: CustomStringConvertible { | |
// array of items | |
var items: [T] = [] | |
// to print the formatted description | |
var description: String { | |
return "---- Stack begin ----\n" + | |
items.map({ "\($0)" }).joined(separator: "\n") + | |
"\n---- Stack End ----" |
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
import Foundation | |
extension Date { | |
func timeAgo() -> String { | |
let secondsAgo = Int(Date().timeIntervalSince(self)) | |
let minute = 60 | |
let hour = 60 * minute |
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
import UIKit | |
// MARK: - IndexPaths | |
extension UICollectionView { | |
var lastIndexPath: IndexPath? { | |
return lastIndexPath(inSection: lastSection) | |
} | |
var lastSection: Int { |
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 UIView { | |
class func gradientViewWithText(text: String, size: CGSize, firstColor: UIColor, secondColor: UIColor, font: UIFont) -> UIView { | |
let view = UIView() | |
let layer = CAGradientLayer() | |
layer.colors = [firstColor.cgColor, secondColor.cgColor] | |
layer.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height) | |
view.layer.addSublayer(layer) | |
let textLabel = UILabel() |
OlderNewer