Skip to content

Instantly share code, notes, and snippets.

View AndreyPanov's full-sized avatar
🤚

Andrei Panov AndreyPanov

🤚
View GitHub Profile
func push(_ module: Presentable?)
@AndreyPanov
AndreyPanov / BaseCoordinator.swift
Created January 12, 2017 16:11
BaseCoordinator
class BaseCoordinator {
var childCoordinators: [Coordinator] = []
// add only unique object
func addDependency(_ coordinator: Coordinator) {
for element in childCoordinators {
if element === coordinator { return }
}
childCoordinators.append(coordinator)
}
@AndreyPanov
AndreyPanov / runCreationFlow.swift
Created January 12, 2017 16:10
runCreationFlow
func runCreationFlow() {
let (coordinator, module) = coordinatorFactory.makeItemCoordinatorBox()
coordinator.finishFlow = { [weak self, weak coordinator] item in
self?.router.dismissModule()
self?.removeDependency(coordinator)
self?.showItemDetail(item)
}
addDependency(coordinator)
router.present(module)
coordinator.start()
@AndreyPanov
AndreyPanov / showItemList.swift
Created January 12, 2017 16:09
showItemList
func showItemList() {
let itemsView = factory.makeItemsView()
itemsView.onItemSelect = { [weak self] (item) in
self?.showItemDetail(item)
}
itemsView.onCreateButtonTap = { [weak self] in
self?.runCreationCoordinator()
}
router.setRootModule(itemsView)
}
@AndreyPanov
AndreyPanov / ItemCoordinator.swift
Created January 12, 2017 16:08
ItemCoordinator
final class ItemCoordinator {
private let factory: ItemModuleFactory
private let coordinatorFactory: CoordinatorFactory
private let router: Router
init(router: Router,
factory: ItemModuleFactory,
coordinatorFactory: CoordinatorFactory) {
self.router = router
self.factory = factory
@AndreyPanov
AndreyPanov / CoordinatorOutput.swift
Created January 12, 2017 16:03
CoordinatorOutput
protocol CoordinatorOutput {
var finishFlow: (Item -> Void)? { get set }
}
@AndreyPanov
AndreyPanov / Coordinator.swift
Created January 12, 2017 16:03
Coordinator
protocol Coordinator: class {
func start()
}
@AndreyPanov
AndreyPanov / PrepareForSegue.swift
Created January 12, 2017 15:59
PrepareForSegue
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "openControllerA" {
let vc = segue.destinationViewController as! ControllerA
vc.monkey = 🐒
} else if segue.identifier == "openControllerB" {
let vc = segue.destinationViewController as! ControllerB
vc.tiger = 🐯
} else if segue.identifier == "openControllerC" {
let vc = segue.destinationViewController as! ControllerC
vc.frog = 🐸
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if 🍌🍌 {
router.openControllerA()
} else if 🍌🍌🍌 {
router.openControllerB()
} else if 🍐 {
router.openControllerC()
} else if 🍐🍐 {
router.openControllerD()
}
@AndreyPanov
AndreyPanov / sethack.m
Created July 5, 2016 13:41 — forked from Catfish-Man/sethack.m
Demonstrating the trick of using stack-allocated mimics and sets for lookup tables instead of heap allocated keys and dictionaries
// Compile with clang -framework Foundation sethack.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
/*
CFHashBytes from http://www.opensource.apple.com/source/CF/CF-1153.18/CFUtilities.c
*/
#define ELF_STEP(B) T1 = (H << 4) + B; T2 = T1 & 0xF0000000; if (T2) T1 ^= (T2 >> 24); T1 &= (~T2); H = T1;