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
| // MARK: Form Validation | |
| @discardableResult | |
| func isValid() -> (Bool, String?) { | |
| var isValid = true | |
| for item in self.formItems { | |
| item.checkValidity() | |
| if !item.isValid { | |
| isValid = false | |
| } |
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
| // MARK: - Reloadable | |
| extension HomeViewController: Reloadable { | |
| var hasData: Bool { | |
| //return if you have data to be currently displayed (from Realm or memory for instance) or not | |
| } | |
| func reloadData() { | |
| // Display progress | |
| // Network call |
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 UIKit | |
| protocol Reloadable { | |
| func reloadData() | |
| var hasData: Bool { get } | |
| } | |
| extension Reloadable where Self: UIViewController { | |
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
| /// Errors prompting protocol | |
| protocol Failable { | |
| /// Show an error | |
| func showError(_ error: Swift.Error?) | |
| } |
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
| /// Errors prompting protocol at its core | |
| protocol FailableCore { | |
| /// Show an error | |
| func showError(_ error: Swift.Error?) | |
| } | |
| /// Failable protocol to display error | |
| protocol Failable: FailableCore { | |
| var errorScreenType: ErrorScreen? {get} |
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
| /// Specify the error display context when hasData is true : use the error message, or use data oriented priority | |
| /// | |
| /// - dataOriented: For this type, the error message will show that data inconsistency is possible | |
| /// - errorOriented: The error message always use the Error type localized message if available, default message if needed | |
| enum ErrorContext { | |
| case dataOriented | |
| case errorOriented | |
| } |
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
| // Type of screen and its error view to display | |
| enum ErrorScreen { | |
| case home | |
| case details | |
| var errorView: ErrorView.Type? { | |
| switch self { | |
| default: | |
| return ErrorViewRetry.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
| protocol ErrorDisplayable { | |
| static func show<T: ErrorView>( | |
| fromViewController viewController: UIViewController, | |
| animated: Bool, | |
| completion: ((Bool) -> Swift.Void)?) -> T | |
| static func show<T: ErrorView>( | |
| fromView view: UIView, | |
| insets: UIEdgeInsets, animated: Bool, | |
| completion: ((Bool) -> Swift.Void)?) -> T |
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 ErrorViewDelegate: class { | |
| func errorView(_ errorView: ErrorView, didRetry sender: UIButton) | |
| } |
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 ErrorAnimatable { | |
| func playAnimation() | |
| func stopAnimation() | |
| } |