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 NSDictionary { | |
var swiftDictionary: [String : AnyObject] { | |
var swiftDictionary: [String : AnyObject] = [:] | |
let keys = self.allKeys.flatMap { $0 as? String } | |
for key in keys { | |
let keyValue = self.value(forKey: key) as AnyObject | |
swiftDictionary[key] = keyValue | |
} | |
return swiftDictionary |
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
protocol Chainable: class { | |
var before: (()->())? { get set } | |
func before(_ callback: @escaping ()->()) -> Self | |
func invoke() | |
} | |
extension Chainable { | |
@discardableResult |
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
func debounce(_ action: @escaping () -> Void) { | |
let lastFireTime = DispatchTime.now() | |
let dispatchDelay = TimeInterval(0.3) | |
DispatchQueue.main.asyncAfter(deadline: .now() + dispatchDelay) { | |
let now = DispatchTime.now() | |
let when = lastFireTime + dispatchDelay | |
if now >= when { | |
action() | |
} |
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
fileprivate enum LaunchInstructor { | |
case main, auth, onboarding | |
static func configure(tutorialWasShown: Bool, isAutorized: Bool) -> LaunchInstructor { | |
switch (tutorialWasShown, isAutorized) { | |
case (true, false), (false, false): return .auth | |
case (false, true): return .onboarding | |
case (true, true): return .main | |
} | |
} |
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
func push(_ module: Presentable?) |
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
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 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 |
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
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 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 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 BaseCoordinator { | |
var childCoordinators: [Coordinator] = [] | |
// add only unique object | |
func addDependency(_ coordinator: Coordinator) { | |
for element in childCoordinators { | |
if element === coordinator { return } | |
} | |
childCoordinators.append(coordinator) | |
} |
NewerOlder