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
| //STEPS TO IMPLEMENT STRATEGY PATTERN ON PROTOCOL ORIENTED MVP VIEWCONTROLLER WITH MVVM CELLS | |
| //1: The ViewController will have a collection of cell viewModels | |
| //2: There must be a drawer class for each cell that implements the cell drawer protocol | |
| //3: Each of the cellViewModels must implement the viewModel generic protocol in order to have a reference to the cellDrawer | |
| //DRAWER AND VIEWMODEL PROTOCOLS | |
| protocol <#YOUR_DRAWER_PROTOCOL_NAME#> { | |
| func cellFor(tableView: UITableView, atIndexPath: IndexPath) -> UITableViewCell | |
| func draw(_ cell: UITableViewCell, cellViewModel: Any, presenter: <#CONTROLLER_PRESENTER_PROTOCOL#>) | |
| func heightFor(tableView: UITableView, atIndexPath: IndexPath, cellViewModel: Any) -> CGFloat |
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
| import Foundation | |
| import UIKit | |
| @IBDesignable public class PaddingLabel: UILabel { | |
| @IBInspectable public var topInset: CGFloat = 5.0 | |
| @IBInspectable public var bottomInset: CGFloat = 5.0 | |
| @IBInspectable public var leftInset: CGFloat = 7.0 | |
| @IBInspectable public var rightInset: CGFloat = 7.0 |
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
| import Foundation | |
| import UIKit | |
| extension UITableView { | |
| public func reloadData(completion:@escaping ()->()) { | |
| UIView.animate(withDuration: 0, animations: reloadData) | |
| { _ in completion() } | |
| } | |
| } |
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
| import Foundation | |
| import UIKit | |
| protocol ReusableView: class { | |
| static var defaultReuseIdentifier: String { get } | |
| } | |
| extension ReusableView where Self: UIView { | |
| static var defaultReuseIdentifier: String { | |
| return String(describing: self) |
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
| import Foundation | |
| import UIKit | |
| protocol NibLoadableView: class { | |
| static var nibName: String { get } | |
| } | |
| extension NibLoadableView where Self: UIView { | |
| static var nibName: String { | |
| return String(describing: self) |
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
| import Foundation | |
| extension UIViewController { | |
| class func loadFromNib<T: UIViewController>() -> T { | |
| return T(nibName: String(describing: self), bundle: nil) | |
| } | |
| } |
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 CALayer { | |
| func addBorder(edge: UIRectEdge, color: UIColor, thickness: CGFloat, inset: CGFloat) { | |
| let border = CALayer() | |
| switch edge { | |
| case UIRectEdge.top: | |
| border.frame = CGRect.init(x: inset, y: 0, width: frame.width - inset * 2, height: thickness) | |
| border.name = "top" |
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 { | |
| static func localized(_ identifier: String) -> String { | |
| return NSLocalizedString(identifier, comment: "") | |
| } | |
| } |
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 UITableView { | |
| func register<T: UITableViewCell>(_: T.Type) where T: NibLoadableView { | |
| let bundle = Bundle(for: T.self) | |
| let nib = UINib(nibName: T.nibName, bundle: bundle) | |
| self.register(nib, forCellReuseIdentifier: T.defaultReuseIdentifier) | |
| } | |
| func registerHeader<T: UIView>(_: T.Type) where T: ReusableView, T: NibLoadableView { |
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 Optional { | |
| //Executes the closure if there is some value | |
| func then(_ handler: (Wrapped) -> Void) { | |
| switch self { | |
| case .some(let wrapped): return handler(wrapped) | |
| case .none: break | |
| } | |
| } | |
NewerOlder