Skip to content

Instantly share code, notes, and snippets.

View thexande's full-sized avatar

Alexander Murphy thexande

  • Ibotta
  • Denver, CO, USA, Planet Earth
View GitHub Profile
@thexande
thexande / interactive_transitions.md
Created December 5, 2020 03:33
A writeup on interactive transitions in UIKit.

Leveraging Interactive Custom View Controller Transitions

At Ibotta, we're constantly striving to provide our savers with the best possible user experience. As an iOS engineer, there are a number of super powerful APIs at my disposal to provide a top noch mobile UX.

One such API is the custom view controller transitioning capabilities contained within UIKit. These protocols provide an interface to control how one view controller is presented over another, and level of customization available to the programmer is significant.

Let's consider the basic use case of a card modal presentation. When a user selects an item on one view, another detail view is presented over the top. The presented detail view can then be dismissed by swiping down. This downward swipe is generally interactive, meaning the view follows the movement of your thumb as you swipe to dismiss.

This pattern is quite common across iOS applications, especially apps which have payment capabilities. With Ibotta's entrance into the payments

@thexande
thexande / GeometryReaderBugInLazyVStack.swift
Created July 11, 2020 19:39
A Swift UI playground displaying a bug when using geometry reader in lazy v grid.
import SwiftUI
import PlaygroundSupport
let ipsum = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
extension CGFloat {
static var random: CGFloat {
return CGFloat(arc4random()) / CGFloat(UInt32.max)
}
}
@thexande
thexande / MatchedGeometryEffectDemo.swift
Created July 11, 2020 00:23
A playground showing how the .matchedGeometryEffect modifier works.
import SwiftUI
import PlaygroundSupport
final class Item: Identifiable {
let color: Color
let id = UUID()
var displayDetail: Bool
init(color: Color, displayDetail: Bool = false) {
self.color = color
self.displayDetail = displayDetail
private func executeShellCommand(_ command: String) {
let task = Process()
let pipe = Pipe()
task.standardOutput = pipe
task.arguments = ["-c", command]
task.launchPath = "/bin/bash"
// task.launch()
let outputHandle = pipe.fileHandleForReading
@thexande
thexande / CoffeeMachine.swift
Created April 10, 2020 22:15
A coffee machine implementation using swift.
protocol ResourcesContaining {
var beans: Double { get set }
var milk: Double { get set }
var water: Double { get set }
func hasRequiredResources(for resourceSet: [Resource]) -> Bool
}
extension ResourcesContaining {
func hasRequiredResources(for resourceSet: [Resource]) -> Bool {
var currentBeans = self.beans
enum Node<T> where T: Equatable & Comparable {
case empty
indirect case value(left: Node<T>, value: T, right: Node<T>)
}
extension Node {
func isValid(within range: ClosedRange<T>) -> Bool {
switch self {
case .empty:
return true
final class CardPresentationCoordinator: UIPercentDrivenInteractiveTransition {
var hasStartedInteraction = false
var shouldFinishTransition = false
}
final class RansomNoteBuilder {
func isValidRansomNote(note: String, in magazine: String) -> Bool {
var lookup = magazine.reduce(into: [Character:Int]()) { dictionary, letter in
dictionary[letter] = (dictionary[letter] ?? 0) + 1
}
for character in note {
guard let count = lookup[character], count > 0 else { return false }
lookup[character] = count - 1
@thexande
thexande / Valid Binary Search Tree.swift
Last active January 22, 2020 05:15
Determine if a given binary search tree is valid.
final class Node {
let left: Node?
let right: Node?
let value: Int
init(left: Node? = nil, right: Node? = nil, value: Int) {
self.left = left
self.right = right
self.value = value
}
let test = "abba"
class Solution {
func expandPalindrome(input: String, startIndex: Int, endIndex: Int) -> (Int, Int) {
var start = startIndex
var end = endIndex
let inputArray = Array(input)
var result = (start, end)