Skip to content

Instantly share code, notes, and snippets.

View AndreyPanov's full-sized avatar
🤚

Andrei Panov AndreyPanov

🤚
View GitHub Profile
@AndreyPanov
AndreyPanov / UIImageExtension.swift
Last active May 24, 2016 07:50
Using unwrap images in project
protocol AssetLoadable {
var rawValue: String { get }
func imageNamed() -> String
}
extension AssetLoadable {
func imageNamed() -> String {
return rawValue
}
extension UITableView {
func animatedInsert(indexPaths paths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation = .Automatic) {
guard paths.isEmpty == false else { return }
beginUpdates()
insertRowsAtIndexPaths(paths, withRowAnimation: animation)
endUpdates()
}
func animatedlReload(indexPaths paths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation = .Automatic) {
@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;
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 / 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 = 🐸
@AndreyPanov
AndreyPanov / Coordinator.swift
Created January 12, 2017 16:03
Coordinator
protocol Coordinator: class {
func start()
}
@AndreyPanov
AndreyPanov / CoordinatorOutput.swift
Created January 12, 2017 16:03
CoordinatorOutput
protocol CoordinatorOutput {
var finishFlow: (Item -> Void)? { get set }
}
@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 / 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 / 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()