Skip to content

Instantly share code, notes, and snippets.

View caldofran's full-sized avatar

Rubén Méndez caldofran

View GitHub Profile

Keybase proof

I hereby claim:

  • I am caldofran on github.
  • I am caldofran (https://keybase.io/caldofran) on keybase.
  • I have a public key ASCrrDUclWHcFz3S3dA6ju6i-pSFpsFWiqDz-NvoPY2OTQo

To claim this, I am signing this object:

@caldofran
caldofran / screen_extensions.swift
Created March 6, 2020 15:37
Screen extensions
extension Screen {
static func offer(id: String) -> Self {
return .init() { OfferViewController(id: id) }
}
}
extension Screen {
static func job(id: String) -> Self {
return .init() { JobViewController(id: id) }
}
@caldofran
caldofran / snapshot_result.txt
Last active March 4, 2020 14:22
An example of the result of a snapshot navigation test
▿ Navigation
▿ modal: (3 elements)
▿ .0: Screen
▿ viewController: <CandidateProcessViewController>
- id: "4224"
- .1: UIModalPresentationStyle.UIModalPresentationStyle
- completion: Optional<() -> ()>.none
@caldofran
caldofran / navigation_test.swift
Last active March 6, 2020 15:30
Example of a snapshot navigation test
func testPresentsRightControllerWhenSelectingARow() {
// Given
let navigatorSpy = NavigatorSpy()
let sut = NotificationCenterViewController(navigator: navigatorSpy)
sut.loadViewIfNeeded()
// When
sut.selectRow(at: .init(row: 0, section: 0))
// Then
@caldofran
caldofran / whole_navigation.swift
Created November 20, 2019 15:33
Whole navigation implementation: Navigation + Navigator
import UIKit
enum Navigation {
case section(Section)
case modal(Screen)
case push(Screen)
}
enum Section: Int {
case home
@caldofran
caldofran / example_navigation.swift
Last active March 3, 2020 15:02
An example of how to use the Navigator
navigator.handle(navigation: .section(.home))
navigator.handle(navigation: .modal(.offer(id: "1")))
navigator.handle(navigation: .push(.job(id: "1")))
@caldofran
caldofran / navigator.swift
Last active March 6, 2020 15:14
Simple Navigator implementation
class Navigator {
func handle(navigation: Navigation, animated: Bool = true) {
switch navigation {
case .section(let section):
tabBarController().selectedIndex = section.rawValue
case .modal(let screen):
topMostViewController().present(
screen.viewController(),
animated: animated
@caldofran
caldofran / navigation.swift
Last active March 6, 2020 15:36
Model navigation with value types
enum Navigation {
case section(Section)
case push(Screen)
case modal(
Screen,
UIModalPresentationStyle = .fullScreen,
completion: (() -> Void)? = nil
)
}
@caldofran
caldofran / traditional_navigation_ios.swift
Last active November 20, 2019 14:16
Example of a very basic navigation on iOS
class ViewControllerA: UIViewController {
func presentViewControllerB() {
navigationController?.pushViewController(ViewControllerB(), animated: true)
}
}
@caldofran
caldofran / NSObject+debugCheck.h
Created June 30, 2015 09:30
Avoid attach runtime processes when debugging
//
// NSObject+debugCheck.h
// Reverse Me
//
// Created by Derek Selander on a happy day.
// Copyright (c) 2013 Derek Selander. All rights reserved.
//
#import <Foundation/Foundation.h>
#include <unistd.h>