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 headerLabel: (UILabel) -> () = { control in | |
control.font = .systemFont(ofSize: 20) | |
control.textColor = .red | |
} | |
var bodyLabel: (UILabel) -> () = { control in | |
control.font = .systemFont(ofSize: 15) | |
control.textColor = .darkGray | |
} | |
var loginTextField: (UITextField) -> () = { control in | |
control.font = .systemFont(ofSize: 15) |
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 Guide { | |
case headerLabel((UILabel) -> ()) | |
case bodyLabel((UILabel) -> ()) | |
case loginTextField((UITextField) -> ()) | |
func identifier() -> String { | |
switch self { | |
case .headerLabel: return "header" | |
case .bodyLabel: return "body" | |
case .loginTextField: return "login" |
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
func guide() -> [Guide] { | |
return [ | |
.headerLabel(headerLabel), | |
.bodyLabel(bodyLabel), | |
.loginTextField(loginTextField) | |
] | |
} |
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
func perform<T>(with identifier: String, closure: (T) -> Void) { | |
Mirror(reflecting: self).children.forEach { property in | |
guard | |
property.label?.contain(identifier) == true, | |
let value = property.value as? T | |
else { return } | |
//run closure | |
closure(value) | |
} | |
} |
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
func applyStyle() { | |
StyleBuilder() | |
.guide() | |
.forEach { setStyle(with: $0) } | |
} | |
private func setStyle(with guide: Guide) { | |
switch guide { | |
case .headerLabel(let closure), | |
.bodyLabel(let closure): |
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
final class Repository { | |
private let dataProdider: DataProvider | |
init(dataProdider: DataProvider = .init()) { | |
self.dataProdider = dataProdider | |
} | |
func getItem(onSuccess: @escaping (Item)->(), onError: @escaping (Error)->()) { | |
//background async request | |
dataProvider.request.items { [weak self] data, error in | |
if let item = ItemBuilder(with: data) { |
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
func onViewLoaded() { | |
view?.showLoadingIndicator() | |
repository.getItem( | |
onSuccess: { [weak self] item in | |
self?.view?.hideLoadingIndicator() | |
print(item.description) | |
}, | |
onError: { [weak self] error in | |
self?.view?.hideLoadingIndicator() | |
print(error.localizedDescription) |
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
func onViewLoaded() { | |
view?.showLoadingIndicator() | |
repository | |
.before({ [weak self] in self?.view?.hideLoadingIndicator() }) | |
.getItem( | |
onSuccess: { [weak self] item in | |
print(item.description) | |
}, | |
onError: { [weak self] error in | |
print(error.localizedDescription) |
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 Chainable: class { | |
var before: (()->())? { get set } | |
func before(_ callback: @escaping ()->()) -> Self | |
func invoke() | |
} | |
extension Chainable { | |
@discardableResult |
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
final class Repository: Chainable { | |
var before: (()->())? | |
private let dataProdider: DataProvider | |
init(dataProdider: DataProvider = .init()) { | |
self.dataProdider = dataProdider | |
} | |
func getItem(onSuccess: @escaping (Item)->(), onError: @escaping (Error)->()) { | |
//background async request |