Skip to content

Instantly share code, notes, and snippets.

View bill350's full-sized avatar

Jean-Charles SORIN bill350

View GitHub Profile
class ProgressView: UIView, NibLoadable {
// MARK: Properties
var animationDuration = 0.3
fileprivate(set) var isAnimating = false
// MARK: - Overrides
override func awakeFromNib() {
super.awakeFromNib()
// MARK: - ErrorAnimatable
extension ErrorView: ErrorAnimatable {
func playAnimation() {
self.isAnimating = true
}
func stopAnimation() {
self.isAnimating = false
}
// MARK: - ErrorDisplayable
extension ErrorView: ErrorDisplayable {
static func show<T: ErrorView>(
fromViewController viewController: UIViewController,
animated: Bool = true,
completion: ((Bool) -> Swift.Void)? = nil) -> T {
guard let subview = loadFromNib() as? T else {
fatalError("The subview is expected to be of type \(T.self)")
class ErrorView: UIView, NibLoadable {
// MARK: Properties
weak var delegate: ErrorViewDelegate?
var animationDuration = 0.3
fileprivate(set) var isAnimating = false
// MARK: - Overrides
override func awakeFromNib() {
super.awakeFromNib()
protocol ErrorAnimatable {
func playAnimation()
func stopAnimation()
}
protocol ErrorViewDelegate: class {
func errorView(_ errorView: ErrorView, didRetry sender: UIButton)
}
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
// 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
}
/// 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
}
/// 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}